English 中文(简体)
当位置.href 在ajax 请求完成前更改时会怎样?
原标题:What will happen when location.href is changed before ajax request completes?
  • 时间:2012-05-27 13:12:45
  •  标签:
  • php
  • ajax
  1. User clicks some link which execute some ajax request - lets say this request takes 20 secs.
  2. Before the request is complete user clicks oder link which redirects (no ajax) whole page to another page.

Ajax 请求会怎么样? 它总是在服务器上完成, 但回应不会到来吗? 或者服务器上的 Ajax 请求将会被“杀死 ” 。

我问是因为我有些脚本需要一些时间运行, 但用户现在不需要结果了, 它只是着火和忘记, 也许在ajax有某些选择, 迫使它不做出回应?

最佳回答

浏览器应该杀死 AJAX 请求, 关闭与服务器的连接; 但是, 这并不意味着您在服务器上的处理也必然会被杀死 :

问题回答

服务器将完成请求, 并不知道客户已“ 移动 ” 。 服务器将像通常一样将回复回复回客户 。 客户将忽略回复 。

所以希望所有服务器都像正常一样发生, 因此“ 火灾和忘记” 方法会有效( 因为客户已经前进, 并且已经“ 忘记 ” ) 。 但如果你想做任何客户端反应( 这会否定“ 忘记 ” 部分 ), 那么新页面将无法拦截响应。 浏览器将忽略它 。





相关问题
ajax login using httpRequest?

I am trying to develop my login script to give feedback to the user if the login is valid or not. Basically if it isn t correct a div box will show saying its wrong, if its correct it will show its ...

Virtual Tour using sketch up, ajax, flash technologies

I want to know if there are existing technology that make your 3d models in sketch into virtual tours, using either Ajax or Flash for web presentation. If there s none, which will be a good approach ...

How can i update div continuously

I have asp.net application where i have a div which showing the value from other site. The value of that site is changing continuously. I want that my div will automatically update in some interval ...