I'm using a wrapper function around jQuery's AJAX function like this:
$.getAjax = function(url, type, callback){
$.ajax({
url: url,
cache: false,
dataType: type,
success: function(){
alert("success");
},
complete: function(XMLHttpRequest, textStatus){
alert("complete");
if (callback != undefined) {
callback();
}
},
error: function (XMLHttpRequest, textStatus, errorThrown){
alert("error");
}
});
}
When I use this with "text" as a dataType it works perfectly even if the url is invalid. When an url is invalid it first calls the error then the complete function. That's OK. But when I use "script" as a dataType it doesn't call anything when the url is invalid. What shall I do to catch HTTP 404 errors and others when I use "script" as a dataType?