我目前正试图使一些ajax帖子之间的跨域遵循本教程,但有些错误的一些数据没有发送。
实际上我的代理脚本是教程的副本这是我的javascript:
$.ajax({
type: 'POST',
data: data + '&origin=' + origin,
url: 'customer.php',
dataType: 'json',
async: false,
success: function(result){
if (result.id && result.quotation_id){
id = result.id;
quotation_id = result.quotation_id;
}
}
});
通过curl:
编写php脚本解决//set POST variables
$url = 'http://my-different-domain.com';
$fields = array();
foreach ($_POST as $key => $value) {
$fields[$key] = urlencode($value);
}
//url-ify the data for the POST
foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; }
rtrim($fields_string,'&');
//open connection
$ch = curl_init();
//set the url, number of POST vars, POST data
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_POST,count($fields));
curl_setopt($ch,CURLOPT_POSTFIELDS,$fields_string);
//execute post
$result = curl_exec($ch);
//close connection
curl_close($ch);