I got into AJAX and am using the MAMP web server and trying to implement a simple script which should show me whether this is working. I tried tracking down the problem by using the status property of XMLHttpRequest(); I found out that it was a problem of type 404 (Page not found) and this is astonishing as I am using JSON file to handle the script which is in the same directory as my ajax script.
Here is the AJAX script:
var xhr = new XMLHttpRequest();
xhr.onload = function() {
if (xhr.status === 200) {
alert("Good");
}
else if(xhr.status === 304)
{
alert("304");
}
else if(xhr.status === 404)
{
alert("404");
}
else
{
alert("500");
}
xhr.open("GET", 'json.json', true);
xhr.send(null);
And here my file json.json:
{
"events" :
[
{
"location" : "San Francisco, CA"
}
]
}
This is really frustrating. Thanks in advance,
Raul Rao
Aucun commentaire:
Enregistrer un commentaire