I am making the following ajax call from my HTTPS page,
$.ajax({
url: "http://www.w3schools.com",
dataType: 'jsonp',
crossDomain: true,
complete: function (e, xhr, settings) {
switch (e.status) {
case 200:
//everything fine
break;
default:
//Somethings wrong, show error msg
break;
}
}
});
But since I am making an HTTP call from an HTTPS page the call gets blocked. I can see a "insecure content warning" in console(CHROME),
but the error is not catched either in complete,error, or success. They simply don't fire at all.
I need to catch the error. Any way I can do this ?
error
Type: Function( jqXHR jqXHR, String textStatus, String errorThrown )
A function to be called if the request fails. The function receives three arguments: The
jqXHR (in jQuery 1.4.x, XMLHttpRequest) object, a string describing the type of error that
occurred and an optional exception object, if one occurred. Possible values for the second
argument (besides null) are "timeout", "error", "abort", and "parsererror". When an HTTP
error occurs, errorThrown receives the textual portion of the HTTP status, such as "Not
Found" or "Internal Server Error." As of jQuery 1.5, the error setting can accept an array
of functions. Each function will be called in turn. Note: This handler is not called for
cross-domain script and cross-domain JSONP requests. This is an [Ajax Event][1].
Try this,
find the status of request using jqXHR.status
$.ajax({
url: "http://www.w3schools.com",
dataType: 'jsonp',
crossDomain: true,
complete: function (e, xhr, settings) {
switch (e.status) {
case 200:
//everything fine
break;
default:
//Somethings wrong, show error msg
break;
}
},
error: function(jqXHR, textStatus, errorThrown){
alert(errorThrown)
},
});