Remote Cross-domain access is not allowed for security reasons, and two cross-domain methods are described below.
One, through the PHP curl
function Curlpost ($url, $params)
{
$postData = ';
foreach ($params as $k => $v)
{
$postData. = $k. ' = '. $v. ' & ';
}
RTrim ($postData, ' & ');
$ch = Curl_init ();
curl_setopt ($ch, Curlopt_url, $url);
curl_setopt ($ch, curlopt_returntransfer,true);
curl_setopt ($ch, Curlopt_header, false);
curl_setopt ($ch, Curlopt_post, Count ($postData));
curl_setopt ($ch, Curlopt_postfields, $postData);
$output =curl_exec ($ch);
Curl_close ($ch);
return $output;
}
Echo curlpost ("Http://111cn.net", Array (' name ' => "Tank"));
Before many people use curl to grasp, the mailbox address Book, but now is not OK. Ha ha.
Ii. using jquery Form,ajax to submit
1, download Jquery.form.js
2,js Code
$ (' #testform '). Submit (function () {
$ (this). Ajaxsubmit ({
Type: ' Post ',//Submit method Get/post
DataType: "JSON",//data type
URL: ' Your URL ',//URL to submit
Success:function (data) {//File returns after submission, typically JSON data
Data can be related to processing here
Alert (' Commit success! ');
}
$ (this). Resetform (); Reset form after submission
});
return false; Prevent forms from automatically submitting events
});
3,php Code
Header ("access-control-allow-origin:*"); Cross-domain permission settings that allow all
Header ("Access-control-allow-origin:http://www.111cn.net"); Only allow 111cn.net to submit data across domains