i have setup my ajax request like
$.ajax({
url: 'ajax.html',
datatype: 'html',
success: function(data) {
$(data).appendTo('body');
},
error: function(xhr, status, e) {
alert('An error occured: ' + status);
}
});
when i trigger an error by specifying a non existent url, i find that status is always null. i tried xhr.statusText
, xhr.responseText
, xhr.status
all returns nothing also. how can i get an error message?
when i try alert(e)
i get
[Exception... "Access to restricted URI denied" code: "1012" nsresult: "0x805303f4 (NS_ERROR_DOM_BAD_URI)" location: "http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js Line: 130"]
but i want something more like page not found. why isit giving me access restricted? and why is status, xhr.statusText etc all null?
it works online but not on localhost, maybe its just some configuration thing
I just tried that on my system and when I point to a non-existing URL, status
is set to error
for me with no problem. However, it should be noted that you should configure your app on the server-side to send a 404 error when it receives a request for a non-existing page.
Is this a cross-domain request? Browsers forbid cross-domain requests using the XmlHttpRequest AJAX technique. The request will not be processed and therefore the target server will not even know about the request, let alone get a chance to return a status code.