jQuery和AJAX响应头 [英] jQuery and AJAX response header

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

问题描述

所以我有这个jQuery的AJAX调用和响应来自服务器302重定向的形式。我想借此重定向并加载在iframe,但是当我尝试查看一个JavaScript警告的头信息,它出现空,即使萤火虫正确看到它。

So I've got this jQuery AJAX call, and the response comes from the server in the form of a 302 redirect. I'd like to take this redirect and load it in an iframe, but when I try to view the header info with a javascript alert, it comes up null, even though firebug sees it correctly.

这里的code,如果它会帮助:

Here's the code, if it'll help:

$j.ajax({
    type: 'POST',
    url:'url.do',
    data: formData,
    complete: function(resp){
        alert(resp.getAllResponseHeaders());
    }
});

我真的没有访问服务器端的东西,以推动URL以响应体,我知道会是最简单的解决方案,因此任何帮助,标题的解析将是非常美妙。

I don't really have access to the server-side stuff in order to move the URL to the response body, which I know would be the easiest solution, so any help with the parsing of the header would be fantastic.

推荐答案

cballou的解决方案将工作,如果你使用的是旧版本的jQuery。在新版本中,你也可以尝试:

cballou's solution will work if you are using an old version of jquery. In newer versions you can also try:

  $.ajax({
   type: 'POST',
   url:'url.do',
   data: formData,
   success: function(data, textStatus, request){
        alert(request.getResponseHeader('some_header'));
   },
   error: function (request, textStatus, errorThrown) {
        alert(request.getResponseHeader('some_header'));
   }
  });

根据文档的XMLHtt prequest对象可在jQuery 1.4。

According to docs the XMLHttpRequest object is available as of jQuery 1.4.

这篇关于jQuery和AJAX响应头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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