jquery post request/response cross-domain
is it possible to make cross-domain jquery post request and get back a response. anyone know the format?
if not, does anyone know what else I can use on the开发者_高级运维 client side in order make the request and get a response?
thanks.
You can't use JSONP for a post.
There are other solutions, such as a local proxy (which obviates the need for JSONP at all, really).
Op has requested more info about a local proxy. By local, I mean local to the server which is serving up the jQuery. This is just a CURL post, which then echos out whatever is coming back in a object called data:
<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://www.example.com');
curl_setopt($ch, CURLOPT_POSTFIELDS,'a=hello&b=world'); // use your post data here.
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$resp = curl_exec($ch);
curl_close($ch);
echo json_encode(array('data'=>$resp));
精彩评论