Cross-Domain Method
For security reasons, direct cross-border access is not allowed, the following describes two kinds of cross-domain method.First, through the php curl
123456789101112131415161718192021function 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://test.com", array ('name' => "tank"));
Previously, many people came with curl, mailbox address book, but now you can not do. Haha.
Second, the use jquery form, ajax submit
1, download jquery.form.js
2, js Code
1234567891011121314151617$ ('# Testform'). Submit (function ()
{
$ (This) .ajaxSubmit ({
type: 'post', // submission get / post
dataType: "json", // data types
url: 'your url', url // required to submit
success: function (data) { // save data after submission of the returned data, usually json data
// Here can make the relevant data processing
alert ('submitted successfully!');
}
$ (This) .resetForm (); // After submitting reset the form
});
return false; // prevents automatic form Submit an event});
3, php codes
header ("Access-Control-Allow-Origin: *"); // cross-domain permissions settings allow all
header ("Access-Control-Allow-Origin: http: //www.test.com"); // only allow test.com
Post A Comment:
0 comments: