如何使用jquery ajax“get”获取响应头位置?
这是我的示例代码
$.ajax({
type: 'GET',
url: 'http://www.url.com',
data: {},
dataType: "json",
success: function(res) { },
error: function(jqXHR) { }
});
最佳答案
为了访问非简单 header (有关简单 header 的更多详细信息,请参阅 http://www.w3.org/TR/cors/),服务器必须在“Access-Control-Expose-Headers”CORS header 中包含您要访问的 header 名称。
因此,除了“Access-Control-Allow-Origin”之外,您进行调用的服务器还必须包含“Access-Control-Allow-Headers” header :
访问控制公开 header :位置
我在 Windows 7(Chrome 23、Safari 5.1.7、Firefox 17 和 Opera 12.11)上对此进行了测试。似乎只有 Chrome 和 Opera 能够通过 getResponseHeader('Location') 方法访问 Location header ,并且仅当服务器响应中包含 Access-Control-Expose-Headers header 时才有效
关于jquery - 如何通过jquery获取responseheader位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10879679/