确定什么jQuery的阿贾克斯()解析字符串重定向到 [英] Determining what jQuery .ajax() resolves a string of redirects to

查看:94
本文介绍了确定什么jQuery的阿贾克斯()解析字符串重定向到的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道,重定向自动执行,那我没有什么/不通过该过程控制。这是好的,但我仍然在我的要求下,最终结束了很感兴趣。是否有可能看到什么URL我的请求,终于结束了在?

I'm aware that redirects are followed automatically, and that I have little/no control over that process. This is fine, but I'm still very interested in where my request ultimately ends up. Is it possible to see what url my request finally ends up at?

我做的不可以要依靠返回的HTML本身告诉我,我在哪里。

I do not want to rely on the returned HTML itself to tell me where I am.

样品code:

var originalURL = '/this/will/be/redirected';
$.ajax({
    url: originalURL,
    dataType: "html",
    success: function(data, statusText, jqXHR) {
        var endPointURL = insertMagicHere();
        alert("Our query to " + original + " ended up at " + endPointURL + "!");
    }
});

我环顾jqXHR它,但至今没有运气。 (虽然,我是新来的这一切,也许是对的在我的眼皮底下)

I'm looking around in jqXHR for it, but no luck so far. (Though, I'm new to all this, probably right under my nose)

推荐答案

据我知道(有testet),其唯一可能的,以检测是否出现了重定向多少重定向发了言(而不是在这里)

So far as I know (and have testet) its only possible to detect IF there has been a redirect and how many redirects were made (but not TO where).

您可以看看我的code:

You can have a look my code:

var xhr = $.ajax({
  url: originalURL,
  dataType: "html",
  success: function(data, statusText, jqXHR) {
    console.log(data);
    console.log(statusText);
    console.log(jqXHR.getAllResponseHeaders());
  }
});

jqXHR.getAllResponseHeaders()在我开发计算机的输出是这样的:

The jqXHR.getAllResponseHeaders() output on my dev machine is like that:

Date: Fri, 05 Aug 2011 01:29:20 GMT
Server: ...
X-Powered-By: ... 
Content-Length: 5 
Keep-Alive: timeout=15, max=98 
Connection: Keep-Alive 
Content-Type: text/html

保持活动:超时= 15,最大= 98 值得有一个深入了解。没有重定向结果在最大= 99 而一个重定向导致最大= 98

The Keep-Alive: timeout=15, max=98 is worth to have a deeper look at. No redirect result in a max=99 while ONE redirect results in a max=98

这篇关于确定什么jQuery的阿贾克斯()解析字符串重定向到的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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