Jsonp Post cross-domain scenario

Source: Internet
Author: User

This article is to tell you about the individual in a project encountered in the Jsonp of the post cross-domain problem resolution process, here to record, sub-items to everyone.

Recently in the project encountered such a problem, about JSONP cross-domain problem, get pass value is OK, but post value is not alive ah, so online read a lot of information on this, the final problem can be solved, today time to share with you.

Description
http://www.t1.com/index.php server-side URL
Of course this is my local configuration, need to change their corresponding address.

Client code:

12345678910111213141516 <script>  $(function(){         var url = ‘http://www.t1.com/index.php‘;    $.ajax({      type:      ‘post‘,      url:      url,      data:      {name:‘wangyulu‘},      dataType:    ‘jsonp‘,      success:function(result){        console.log(result);      }    });       }); </script>

Service-Side code:

12345 <?php if ( $_post &NBSP;&NBSP; $arr = array ( Code class= "PHP string" > ' name ' => $_post [ ' name ' ], Code class= "PHP string" > ' age ' =>23); &NBSP;&NBSP; echo json_encode ( $arr

Browsers Run as:

Look at the results of the operation, even if the set transfer mode for Post,jquery will be automatically converted to get, Jsonp really does not support the Post mode submission, continue to toss ...

Toss until now finally found in the StackOverflow some information on this aspect, it seems that the foreigner also encountered such a problem ah, address affixed to everyone
Http://stackoverflow.com/questions/3860111/how-to-make-a-jsonp-post-request-that-specifies-contenttype-with-jquery

Key points such as:

See we found that there are changes in the arrow mark, first of all, no matter how much, toss so long, the first corresponding put in the program again, if you can

Client changes:
Added: Crossdomain:true
Modified: DataType: "JSON"

Service Side add:
Header (' access-control-allow-origin: * ');
Header (' Access-control-allow-methods:post ');
Header (' access-control-max-age:1000 ');

Running results such as:

Transferred from: http://www.jb51.net/article/68980.htm

Jsonp Post cross-domain scenario

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.