I have a simple ajax call:
$.ajax({url: my_url_here,
dataType: 'text',
success: function(data, textStatus) {
if(textStatus == "success") {
alert('success');
}
else {
alert('fail');
}
},
error: function(XMLHttpRequest, textStatus, errorThrown) {
//do stuff
}
});
If I run this in a simple HTML file, I get the alert as expected. However if I run this in one of my ASP.NET MVC views, the ajax runs fine, but the callback function is never reached. I have tried creating a blank View page with nothing in it except jQuery and this script, to rule out any conflicts with my other Javascript.
I can see the request in Firebug, and it is returning a 200 response as expected, but it just doesn't reach the callback.
I have tried adding cache: false
paramater, played around with asynch
paramater, nothing seems to do the trick...
Any clues?
EDIT: Updated my jQuery with the error callback as suggested.
Error callback is reached in the View page, (not in the simple html test page however), and I get the following:
XMLHttpRequest.status is "0"
textStatus is "error"
errorThrown is "undefined"
EDIT 2 I should note that the URL I am requesting does not actually return anything, I am just trying to see if it exists- if I view the URL in my broswer it presents a simple text string. Am I using the wrong approach to this?
Why would it work fine in a simple HTML doc, but not within the ASP.NET MVC View? Does ASP do something to the ajax requests?
EDIT 3
So it turns out I was trying to access an external site, which is not allowed.
Seems odd that I was doing that fine from the simple test HTML file, and only ran into problems when I was using the View page...