php跨form提交方法

1.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://test.com",array('name'=>"tank"));

2.jquery ajax

$('#testform').submit(function() {
 $(this).ajaxSubmit({
 type: 'post', // 提交方式 get/post
 dataType:"json",//数据类型
 url: 'your url', // 需要提交的 url
 success: function(data) { // data 保存提交后返回的数据,一般为 json 数据
 // 此处可对 data 作相关处理
 alert('提交成功!');
 }
 $(this).resetForm(); // 提交后重置表单
 });
 return false; // 阻止表单自动提交事件
});

3.header

header("Access-Control-Allow-Origin:*"); //跨域权限设置,允许所有

header("Access-Control-Allow-Origin:http://www.test.com"); //只允许test.com跨域提交数据

 

posted @ 2017-05-31 14:02  侠岚之弋痕夕  阅读(241)  评论(0编辑  收藏  举报
Where is the starting point, we don't have a choice, but the destination where we can pursue!