This seems to be a very basic question, but it took my couple of hours as i am not much aware of javascript and jquery.
Well, i need to parse the Json string and get the value of particular key.
Json looks like: {"currentCT":"Brijesh"}
I tried eval()
and parse()
but it seems i am missing something and i am not able to trace the issue.
I tried:
pre.innerHTML = eval('(' + res + ')');
and
pre.innerHTML = JSON.parse(res);
Both are not working for me.
Output
Both methods returns [object Object]
Point out my mistake
EDIT
<script type="text/javascript">
function findTeacher() {
var url = "/TemplateTest/add/findclassteacher.action?";
var standard = document.getElementById("classes_widget");
var val_standard = "standard="
+ standard.options[standard.selectedIndex].value;
url = url + val_standard + "&";
var section = document.getElementById("sections_widget");
var val_section = "section="
+ section.options[section.selectedIndex].value;
url = url + val_section;
var xmlhttp;
if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp = new XMLHttpRequest();
} else {// code for IE6, IE5
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
var res = xmlhttp.responseText;
var pre = document.getElementById("holder");
pre.innerHTML = JSON.parse(res);
pre.innerHTML = eval('(' + res + ')');
}
}
xmlhttp.open("GET", url, true);
xmlhttp.send();
}
</script>