ajax设置自定义请求头信息


 

客户端请求

$.ajax({
type:"post",
url:urlstr,
dataType:'json',
async:true,
headers:{token:'abck'},
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')) . ')');
* */
}


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM