I am writing a very very simple script in html to parse json data but I am not getting the output in the browser for the div element? Iam sure I am doing a stupid thing somewhere but not getting that.
HTML,JS,JQUERY
<h1>Ajax Hellow World</h1>
<script type="text/javascript" >
$(document).ready(function () {
var xhr = new XMLHttpRequest();
xhr.open("GET", "JSON/MyList.json", true);
xhr.setRequestHeader("Content-type", "application/json", true);
xhr.onreadystatechange = function () {
if (xhr.readyState == 4 && xhr.status == 200) {
var data = JSON.parse(xhr.response);
$('#results').html(data.user);
}
}
xhr.send(null);
$('#results').html("Working...........");
});
</script>
<div id="results"></div>
MyList.json is located in JSON Folder.
JSON File
{ "user":"John", "Age":44, "Location":"LA" }
onreadystatechange
ever get called? If it does, is thexhr.response
what you actually expect it to be?}
just abovexhr.send(null);