jQuery and AJAX response header(jQuery 和 AJAX 响应标头)
问题描述
所以我得到了这个 jQuery AJAX 调用,并且响应以 302 重定向的形式来自服务器.我想采用此重定向并将其加载到 iframe 中,但是当我尝试使用 javascript 警报查看标头信息时,它显示为 null,即使 firebug 正确地看到它.
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.
这是代码,如果有帮助的话:
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.
推荐答案
如果您使用的是旧版本的 jquery,cballou 的解决方案将可以工作.在较新的版本中,您也可以尝试:
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'));
}
});
根据文档 XMLHttpRequest 对象从 jQuery 1.4 开始可用.
According to docs the XMLHttpRequest object is available as of jQuery 1.4.
这篇关于jQuery 和 AJAX 响应标头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:jQuery 和 AJAX 响应标头


- 如何向 ipc 渲染器发送添加回调 2022-01-01
- 为什么我的页面无法在 Github 上加载? 2022-01-01
- 在不使用循环的情况下查找数字数组中的一项 2022-01-01
- 如何显示带有换行符的文本标签? 2022-01-01
- 为什么悬停在委托事件处理程序中不起作用? 2022-01-01
- 使用 iframe URL 的 jQuery UI 对话框 2022-01-01
- 从原点悬停时触发 translateY() 2022-01-01
- 如何调试 CSS/Javascript 悬停问题 2022-01-01
- 我不能使用 json 使用 react 向我的 web api 发出 Post 请求 2022-01-01
- 是否可以将标志传递给 Gulp 以使其以不同的方式 2022-01-01