0

I wrote a jsp which request to the servlet and return a json to my jsp ,my problem is that I want to iterate on json and show it in my page ,but I do not know how to get my json in my javascript function . I do not want to use jquery ui an ajax . I want to write it in pure javascript and jsp . tnx for ur help.

Mina
  • 139
  • 1
  • 4
  • 19

2 Answers2

0

Try something like this,

var json = xmlHTTPRequest.responseText,
obj = JSON.parse(json);
alert(objJSON.result);
alert(objJSON.count);
Nirmal
  • 4,789
  • 13
  • 72
  • 114
0

Assuming you are already holding the JSON somewhere within your JSP, this examples shows how to access JSP content from a javascript function: JSP/JavaScript-Example. If my assumption is wrong, you maybe want to post your code for further suggestions.

Community
  • 1
  • 1
Ben-G
  • 4,996
  • 27
  • 33
  • I know the best way is using ajax but I was told to do this without using ajax !! – Mina Jul 22 '12 at 07:13
  • Assuming you are already holding the JSON somewhere within your JSP, this examples shows how to access JSP content from a javascript function: [JSP/JavaScript-Example](http://stackoverflow.com/questions/4803906/jsp-variable-accssing-in-javascript). If my assumption is wrong, you maybe want to post your code for further suggestions. – Ben-G Jul 23 '12 at 07:26
  • Just changed the content of my answer, to the content of the comment. You may want to mark it as correct answer. – Ben-G Jul 31 '12 at 06:58