如何从jQuery获取响应头位置? [英] How to get Response Header location from jQuery Get?

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

问题描述

所以我试图通过jQuery get从头响应中获取位置。我尝试使用getResponseHeader('Location')和getAllResponseHeaders(),但它们似乎都返回null。

So I am trying to get the location from a header response via jQuery get. I tried using getResponseHeader('Location') and getAllResponseHeaders() but they both seem to return null.

这是我当前的代码

$(document).ready(function(){
   var geturl;
   geturl = $.ajax({
      type: "GET",
      url: 'http://searchlight.cluen.com/E5/Login.aspx?URLKey=uzr7ncj8)',
   });
   var locationResponse = geturl.getResponseHeader('Location');
   console.log(locationResponse);
});


推荐答案

异步时,标题将可用请求返回,因此您需要在成功回调中阅读它们:

The headers will be available when the asynchronous request returns, so you will need to read them in the success callback:

$.ajax({
    type: "GET",
    url: 'http://searchlight.cluen.com/E5/Login.aspx?URLKey=uzr7ncj8)',
    success: function(data, status, xhr) {
        console.log(xhr.getResponseHeader('Location'));
    }
});

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

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