I know this question has been answered several times on SO itself. However, I was looking for more clarification with my particular example. I was hoping someone could please further explain the reason why this is happening with the following code.
<script>
function get (url, callback) {
var request = new XMLHttpRequest();
request.open("GET", "file:///C:/Circles/demos/data1.json");
request.onreadystatechange = function () {
alert(request.status);
if (request.readyState === 4 && request.status === 200) {
var type = request.getResponseHeader("Content-Type");
if (type === "application/json") {
callback(JSON.parse(request.responseText));
}
else callback(request.responseText);
}
};
request.send(null);
}
get();
</script>
I get the readyState as 4, but the status is 0. I'm trying this on Google Chrome. I want to try and parse the JSON file.
Please note I'm trying to parse a local JSON file. Any pointers on how to parse a local JSON file would be appreciated.