sunny0120

客户端请求

$.ajax({
type:"post",
url:urlstr,
dataType:\'json\',
async:true,
headers:{token:\'abck\'},
/*  
beforeSend: function (xhr) {
 //发送ajax请求之前向http的head里面加入验证信息
xhr.setRequestHeader("token", abck); // 请求发起前在头部附加token
},
*/ success:function (data) { console.log(data.info); console.log(JSON.stringify(data)); }, error:function (xhr,text) { alert(text); } });

  

  

 

服务端代码

public function test_jsonp()
{
header("Access-Control-Allow-Headers: token");
$arr = getallheaders();
foreach($arr as $key=>$val){
$data[$key] = $val;
}
//	echo $callback .\'(\' . json_encode($data) . \')\';
echo json_encode($data);
exit;	
/*
* 或者可以这样合并写 exit($callback .\'(\' . json_encode(array(\'info\'=>\'jsonp test success\')) . \')\');
* */	
}

  

分类:

技术点:

相关文章:

  • 2021-12-05
  • 2022-12-23
  • 2022-12-23
  • 2021-11-28
  • 2021-11-28
  • 2021-11-28
  • 2021-11-28
猜你喜欢
  • 2021-04-17
  • 2021-11-28
  • 2021-07-17
  • 2021-11-28
  • 2021-10-05
相关资源
相似解决方案