jquery - Exception handling in Ajax -
i making following ajax call 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 making http call https page call gets blocked. can see "insecure content warning" in console(chrome),
but error not catched either in complete,error, or success. don't fire @ all.
i need catch error. way can ?
error type: function( jqxhr jqxhr, string textstatus, string errorthrown ) function called if request fails. function receives 3 arguments: jqxhr (in jquery 1.4.x, xmlhttprequest) object, string describing type of error occurred , optional exception object, if 1 occurred. possible values second argument (besides null) "timeout", "error", "abort", , "parsererror". when http error occurs, errorthrown receives textual portion of http status, such "not found" or "internal server error." of jquery 1.5, error setting can accept array of functions. each function called in turn. note: handler not called cross-domain script , cross-domain jsonp requests. [ajax event][1].
try this,
find 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) }, });
Comments
Post a Comment