PDA

View Full Version : JSON.parse response


niladhar
03-24-2010, 05:01 PM
I am tryin to get data through json on the fly and display it on the browser, although i get the content coded perfectly in json it doesnt parse it and display it.




if (xmlhttp.readyState==4)
{
alert(xmlhttp.responseText);

var theResponse = JSON.parse(xmlHttp.responseText);
document.getElementById('task_area').innerHTML = theResponse.firstResponse;
document.getElementById('active_area').innerHTML = theResponse.secondResponse;
}


The alert shows me

{"firstResponse":"hello world","secondResponse":"hello america"}


Thus i have the responsetext formatted correctly in json but i gues it just doesnt parse it.... any help.... i have json2.js (json lib) including in the same html file as i have this javascript file included in.

rnd me
03-24-2010, 05:57 PM
what does this do:

document.getElementById('task_area').innerHTML = "Can you hear me now?"

EDIT:
javascript is case-sensitive, check your "H"s...

niladhar
03-24-2010, 06:00 PM
what does this do:

document.getElementById('task_area').innerHTML = "Can you hear me now?"

EDIT:
javascript is case-sensitive, check your "H"s...

thats pretty simple... it displays Can you hear me now? in the div area id'd task_area

Kor
03-24-2010, 09:12 PM
What kid of element had the id="task_area"? What Doctype are you using? On which browser? heve you followed the tutorial on:
http://www.json.org/fatfree.html
?