在網(wǎng)上找到了這種方法:$.ajax({ //請(qǐng)求類型,這里為POST
type: 'POST', //你要請(qǐng)求的api的URL
url: url , //是否使用緩存
cache:false, //數(shù)據(jù)類型,這里我用的是json
dataType: "json",
//必要的時(shí)候需要用JSON.stringify() 將JSON對(duì)象轉(zhuǎn)換成字符串
data: JSON.strigify({key:value}), //data: {key:value},
//添加額外的請(qǐng)求頭
headers : {'Access-Control-Allow-Origin':'*'}, //請(qǐng)求成功的回調(diào)函數(shù)
success: function(data){ //函數(shù)參數(shù) "data" 為請(qǐng)求成功服務(wù)端返回的數(shù)據(jù)},});但是提示:Request header field Access-Control-Allow-Origin is not allowed by Access-Control-Allow-Headers in preflight response.已經(jīng)在php代碼里吧 Access-Control-Allow-Headers的值設(shè)置為*了,還是報(bào)錯(cuò),有沒(méi)有解決辦法?
jquery用post方法請(qǐng)求數(shù)據(jù),怎么在header里傳參?
萬(wàn)千封印
2018-08-13 10:09:52