如何通过jQuery获取ResponseHeader位置 [英] How to get responseheader location by jquery

查看:571
本文介绍了如何通过jQuery获取ResponseHeader位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用jquery ajax"get"获取响应头的位置?

how to get response header location with jquery ajax "get"?

这是我的示例代码

$.ajax({
    type: 'GET',
    url: 'http://www.url.com',
    data: {},
    dataType: "json",
    success: function(res) { },
    error: function(jqXHR) { }
});

推荐答案

为了访问非简单标头(请参见

In order to access a non simple header (see http://www.w3.org/TR/cors/ for more details about simple headers) the server must include the header name you want to access in "Access-Control-Expose-Headers" CORS header.

因此,除了"Access-Control-Allow-Origin","Access-Control-Allow-Headers"标头之外,您在其上进行呼叫的服务器还必须包括:

So, besides "Access-Control-Allow-Origin", "Access-Control-Allow-Headers" headers the server on which you make the call must include:

访问控制公开标题:位置

Access-Control-Expose-Headers: Location

我在Windows 7(Chrome 23,Safari 5.1.7,Firefox 17和Opera 12.11)上对此进行了测试.似乎只有Chrome和Opera才能通过getResponseHeader('Location')方法访问Location标头,并且仅当服务器响应中包含Access-Control-Expose-Headers标头时才可以访问

I tested this on Windows 7 (Chrome 23, Safari 5.1.7, Firefox 17 and Opera 12.11). It seems that only Chrome and Opera are able to access the Location header via getResponseHeader('Location') method, and this only if Access-Control-Expose-Headers header is included in the server response

这篇关于如何通过jQuery获取ResponseHeader位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆