【发布时间】:2016-06-11 00:25:10
【问题描述】:
我正在使用 jquery 进行跨源 ajax 请求,我想像这样在请求中设置标头 - 但它说这是一个不正确的请求:
$.ajax({
url: address,
headers:{
'Access-Control-Allow-Origin': '*'
}
success: function(result) {
pipelineCallback(result, guid_key, j, missing_program);
},
error: function(result) {
console.log(result);
},
async: true
});
警告:当我不设置标头并使用此 CORS chrome 插件时,跨域请求可以正常执行...有什么问题?
插件链接(也有一个公共 github 仓库): https://chrome.google.com/webstore/detail/allow-control-allow-origi/nlfbmbojpeacfghkpbjhddihlkkiljbi?hl=en
【问题讨论】:
-
如果可行,为什么还要添加标题?
-
需要设置服务器使用header。
-
服务器确实使用了标头——我是说我不想使用插件来设置请求的标头。我想在请求上手动设置标头。
标签: javascript jquery ajax cross-domain