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