- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个由 servlet 驱动的网络应用程序,它会在一段时间不活动后通过重定向到登录页面使用户 session 超时。我在检查这一点的网络客户端上有适当的代码,基本上类似于以下内容:
function error(request, errtype) {
if (request.status == 302) {
// Display a "timed out" dialog, then:
window.location = request.getResponseHeader("Location");
}
}
但是,最近这个方案失效了;超时时,request.status 为 0。使用 Firebug 我可以看到返回了相同的 HTTP 302 响应。
我仔细阅读了 XMLHttpRequest 的规范,发现了这一部分:
If the redirect does not violate security (it is same origin for instance), infinite loop precautions, and the scheme is supported, transparently follow the redirect while observing the same-origin request event rules.
Otherwise, this is a network error.
我什至不知道客户端应该自动遵循他们为响应 Ajax 请求而获得的重定向;我关心的浏览器以前没有这样做,因为我上面的代码曾经工作过。我最近升级了我的 Firefox 版本,它现在可能更严格地遵循规范。规范规定的网络错误可以解释我看到的零响应代码。但是,我得到的重定向是同一台主机(尽管在不同的端口上),不应该出现无限循环,并且该方案仍然是 HTTP,所以我不明白为什么我会收到网络错误.
有什么想法吗?
最佳答案
你是如何实现这个功能的?如果你只是在 200 状态下将它发送到“错误”,显然这是行不通的......
request.onreadystatechange = function( )
{
if( this.readyState == 4 )
{
// if we got a 200
if( this.status == 200 ){ /* cool */ }
// if we got anything else
else { error( this, this.status ); }
}
};
但我假设您知道这一点。此外,您可能应该在 window.location
的末尾包含 .href 并且可能包含默认位置以防万一
// Display a "timed out" dialog, then:
window.location.href = request.getResponseHeader("Location") || defaultPage;
如果这不起作用,您可能想在 onreadystatechange
方法中尝试不同的状态,因为某些浏览器可能会将非 200 状态解释为错误。这些可能是(来自您正在阅读的同一规范):
0 (if it's considered aborted after unset, though unlikely)
2 (headers-sent) as that 302 code is actually a HTTP header
祝你好运!
关于javascript - Firefox XMLHttpRequest 在 302 响应上设置错误标志,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1924551/
我只需要以下代码的清晰解释来创建 XMLHttpRequest . var xhr = false; if (window.XMLHttpRequest) { xhr = new XMLHtt
我无法让 XMLHttpRequest 对象在我正在编写的仪表板小部件中正常工作。我将其隔离为一个在 main.js 文件的全局范围内不起作用的简单示例: xhr = new XMLHttpR
首先,如果我要说的没有任何意义,请允许我道歉。我已经离开了我的舒适区,我真的不知道我在做什么。照这样说... 我正在使用 Google Drive File Picker library允许用户从他们
我还有一个问题。 XMLhttpRequests 困扰着我。一切现在都在数据库中,但我需要这些数据来更新我的页面以加载或重新加载第一页。 XHR 在触发 PHP 脚本的 JavaScript 文件中触
我试图了解从 WebAssembly 调用 XmlHttpRequest 的最佳和最有效的方法是什么。 我找到了 http://webassembly.org/getting-started/js-a
我有兴趣只提取 XHR 的网址,而不是网页中的每个网址: 这就是我提取页面中每个 url 的代码: import scrapy import json from scrapy.selector imp
有没有办法检测 XmlHttpRequest 无法解析 URL?使用错误的 URL 调用 Open(...) 时似乎不会抛出异常。 最佳答案 HTTP 状态代码将为零。 这适用于无法建立连接且未使用代
有没有办法检测 XmlHttpRequest 无法解析 URL?使用错误的 URL 调用 Open(...) 时似乎不会抛出异常。 最佳答案 HTTP 状态代码将为零。 这适用于无法建立连接且未使用代
当我在 mozilla 浏览器中运行该应用程序时,出现以下错误 主线程上的同步 XMLHttpRequest 已被弃用,因为它会对最终用户的体验产生不利影响。更多帮助 http://xhr.spec.
我正在使用 javascript 通过 XMLHttpRequest 在 div 中加载数据,现在我想知道是否有可能在加载的 div 中创建另一个 XMLHttpRequest,这样一个新的 oncl
这个问题在这里已经有了答案: Are 'Arrow Functions' and 'Functions' equivalent / interchangeable? (4 个答案) 关闭 3 年前。
我感觉到很多关于使用新的 HTML5 JS XHR 技术的简单跨域 XmlHttpRequest 方法的讨论。给定下面的标准 JavaScript XHR 代码... var xhr=new XM
我是 PWA 的初学者,我尝试让我的代码调用 API,然后将其存储在浏览器的缓存中。但是我看到 axios 使用 XMLHttpRequest 而不是 fetch API,所以我无法缓存我的 API
这个问题在这里已经有了答案: Can we omit parentheses when creating an object using the "new" operator? (6 个答案) 关闭
这段代码块有什么区别: var xhr = new XMLHttpRequest(); xhr.upload.addEventListener("progress", uploadProgress,
我有一个 ajax 调用,我在其中使用 jQuery.ajax() 向 mvc 操作发出请求。这一切都很好。但是,由于某些表单具有文件控件,我将其从使用 jQuery.ajax() 更改为使用 XML
我对 Node.js 和 XMLHttpRequest 非常陌生,所以如果这是一个简单答案的问题,请耐心等待。 我目前正在尝试抓取一个 friend 的网页(当然要经过他的许可),其中包含视频和字幕。
我在 Microsoft Edge 中收到此错误。这是什么意思?在线搜索主要是为我提供有关人们在产品中遇到错误的线索。 最佳答案 如果 XMLHttpRequest 调用 ( www.mysite.s
我正在使用 jQuery 和 Office JS API 构建一个 Outlook 加载项。我在开发时有一个本地服务器正在运行,我正在尝试向我站点的主服务器上的端点提交一个 POST 请求。每次尝试提
当使用 FormData 对象将文件附加到请求时,我一直试图找到一种方法来在 XMLHttpRequest 对象上设置我自己的边界。我看过很多关于这个的帖子,每个人都说“不要设置边界,它会自动为你生成
我是一名优秀的程序员,十分优秀!