JSONP solves the problem of Cross-domain Ajax invocation. Why cross Domain Ajax calls? This can be in an application directly in front of the front-end through JS invoke another application (under different domain name) API.
We also use the JSONP in the actual application, but only then knew only one limit of JSONP, can only send GET request, the flaw of the request is the limitation of the length of requests.
Today, the discovery of another limitation of JSONP (in the jquery Ajax scenario)-does not trigger $.ajax's error callback, as follows:
$.ajax ({
dataType: ' Jsonp ',
error:function (XHR) {
//error does not execute this callback function
}
});
This restriction is determined by the JSONP implementation mechanism.
Find two pieces of information on the internet about this issue:
[JQuery]. Ajax () with DataType: ' Jsonp ' won't use error callback if request fails
JSONP error handling with Jquery.ajax
More Wonderful content: http://www.bianceng.cnhttp://www.bianceng.cn/webkf/ajax/
Workaround:
Using a jquery plugin--jquery-jsonp,https://github.com/jaubourg/jquery-jsonp
Sample code:
<script src= "Https://raw.github.com/jaubourg/jquery-jsonp/master/src/jquery.jsonp.js" ></script>
$.jsonp ({
URL: ',
success:function (data) {
},
error:function (xoptions, textstatus) {
Console.log (Textstatus);
}
);
When a JSONP request fails, such as a 404 error, the error callback function executes, and the output string "error".