Cross-domain Access

Source: Internet
Author: User

For security reasons, direct cross-domain access is not allowed, and here are two ways to cross-domain.

one, via PHP curl

1 functionCurlpost ($url,$params)2 {3  $postData= ' ';4  foreach($params  as $k=$v)5  {6  $postData.=$k. ' = '.$v.‘ & ';7  }8  RTrim($postData, ' & ');9  $ch=curl_init ();Tencurl_setopt ($ch, Curlopt_url,$url); Onecurl_setopt ($ch, Curlopt_returntransfer,true); A  -curl_setopt ($ch, Curlopt_header,false); -curl_setopt ($ch, Curlopt_post,Count($postData)); thecurl_setopt ($ch, Curlopt_postfields,$postData);  -  -  $output=curl_exec ($ch); -  +Curl_close ($ch); -  return $output; + } A  at EchoCurlpost ("http://test.com",Array(' name ' = "Tank"));

A lot of people used curl to catch the email address book, but now it is not possible. Ha ha.

Two, submit using jquery Form,ajax

1, download Jquery.form.js

2,JS Code

1$ (' #testform '). Submit (function() {2$( This). Ajaxsubmit ({3Type: ' Post ',//How to submit Get/post4DataType: "JSON",//Data Type5URL: ' Your URL ',//URLs that need to be submitted6Successfunction(data) {//data that is returned after the commit is saved, typically JSON data7  //data can be processed here8Alert (' Submit success! ‘);9  }Ten$( This). Resetform ();//Reset form after submission One  }); A  return false;//prevent forms from automatically submitting events -});

3,php Code

1 Header // cross-domain permission settings, allowing all Header // only allow test.com to submit data across domains

Cross-domain Access

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.