为什么我的 Ajax 请求直接从状态 1 转到状态 4?
我正在使用 AJAX 向 CGI 程序发出请求。 响应向我发送内容长度。 我的目的是动态展示响应进度。 为此,我需要在 XHR 对象的 onreadystate 值为 3 的情况下启动一个函数。但请求似乎并未获取该状态号。 相反,它直接从状态 1 进入状态 4。 我缺少什么?
I am making a request to a CGI program using AJAX. The response sends me content-length. My purpose is to dynamically exhibit the response progress. For that I need to start a function on onreadystate value of XHR object to be 3. But the request doesn't seems to acquire that status number. Instead it goes directly from state 1 to state 4.
What am I missing?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
响应可能进行得如此之快,以至于您在状态 3 时根本没有注意到它。特别是如果您在本地主机上运行它,则响应可能会传输得非常快。 您可以尝试在到达第 3 阶段时设置警报,以测试它是否真正到达该阶段。 另外,我相信 Internet Explorer 表示在第 3 阶段访问响应是错误的,因此可能存在兼容性问题。
The response could be going so quickly that you just don't notice it at state 3. Especially if you are running it on localhost, the response could be transmitted very quickly. You could try setting an alert when it gets to stage 3 to test whether it's actually getting there. Also, I belive internet explorer says that it is a mistake to access the response in stage 3 so there could be compatibility issues.
如果您在本地主机上运行,那么浏览器可能永远没有机会在发送请求的时间和获得响应的时间之间运行...
长话短说:不要指望进入“接收”状态。
If you're running on localhost, then probably the browser is never getting a chance to run between the time it sends the request and the time it gets the response...
Long story short: don't count on going into the "receiving" state.