js代码:
var requert = $.ajax({
url: object.url
data: object.data || '',
type: object.method || 'POST',
dataType: object.dataType || 'json',
headers:{
'token':'1233211234567'
},
success: function(res){
// console.log(res)
object.success(res);
},
error: function (res,errMsg) {
throw errMsg
},
complete: function (param) {
// console.log(param);
}
})
if(object && object.ajaxParam){
object.ajaxParam(requert);
}
}
加上 headers 之后,就一直报错,
Access to XMLHttpRequest at 'http://101.132.158.167:86/index.php/index/index/lishiclass' from origin 'null' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.
然后我在 php 端加上:
header('Access-Control-Allow-Origin:*');
header('Access-Control-Allow-Credentials: true');
header('Access-Control-Allow-Methods:PUT,POST,GET,DELETE,OPTIONS');
header('Access-Control-Allow-Headers:X-Requested-With,token,origin');
header('Content-Type:application/json;charset=utf-8');
也无法解决问题,有没有大神帮帮忙,谢谢