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