Cross-origin javascript-jQueryajax

Source: Internet
Author: User
Why is the error method executed after jQueryjsonp is successfully used for cross-origin? The Code is as follows: HTML part {code ...} PHP file (test. php) {code ...} in addition, I hope that the front-end experts can answer the question. the code for executing the error method after jQuery jsonp cross-origin is successful is as follows:
HTML section

$. Ajax ({type: 'get', ype: 'jsonp', url: "http://XXXX.com/test.php? Jsoncallback = success_jsonpCallback ", // call the custom function success: function (msg) {alert (msg) ;}, error: function (msg) {alert (123 ); alert (msg) ;}}); function success_jsonpCallback (result) {alert (result. img_url );}

Php file (test. php)

$data['status'] = "1";$data['img_url'] = "http://www.baidu.com/img/baidu_jgylogo3.gif";$jsoncallback = $_GET['jsoncallback'];//var_dump($_GET['jsoncallback']);echo $jsoncallback."(".json_encode($data).")";

In addition, I hope that the front-end experts can answer the question.

Reply content:

The code for executing the error method after jQuery jsonp cross-origin is successful is as follows:
HTML section

$. Ajax ({type: 'get', ype: 'jsonp', url: "http://XXXX.com/test.php? Jsoncallback = success_jsonpCallback ", // call the custom function success: function (msg) {alert (msg) ;}, error: function (msg) {alert (123 ); alert (msg) ;}}); function success_jsonpCallback (result) {alert (result. img_url );}

Php file (test. php)

$data['status'] = "1";$data['img_url'] = "http://www.baidu.com/img/baidu_jgylogo3.gif";$jsoncallback = $_GET['jsoncallback'];//var_dump($_GET['jsoncallback']);echo $jsoncallback."(".json_encode($data).")";

In addition, I hope that the front-end experts can answer the question.

Error handler is an Ajax Event.

This handler is not called for cross-domain script and cross-domain JSONP requests.

We recommend that you use the jsonp and jsonpCallback parameters.

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.