Jsonp restrictions in jqueryajax _ jquery

Source: Internet
Author: User
This article describes how to solve the restrictions when using jsonp in jqueryajax. You can refer to this method to solve cross-origin ajax calls. Why cross-origin ajax call? In this way, the API of another application (under different domain names) can be called directly at the frontend through js in an application.
We have also used jsonp in practical applications, but we only know one restriction of jsonp before and can only send get requests. The disadvantage of get requests is that the request length is limited.
Today, we found another restriction of jsonp (in the case of jquery ajax) -- the error callback of $. ajax will not be triggered. The sample code is as follows:

The Code is as follows:


$. Ajax ({
DataType: 'jsonp ',
Error: function (xhr ){
// The callback function is not executed when an error occurs.
}
});

This restriction is determined by the implementation mechanism of jsonp.

Solution:

Use a jquery plugin -- jquery-jsonp, https://github.com/jaubourg/jquery-jsonp

Sample Code:

The Code is as follows:


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.