What will happen when location.href is changed before ajax request completes?

前端 未结 2 505
Happy的楠姐
Happy的楠姐 2020-12-11 09:37
  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 redire
相关标签:
2条回答
  • 2020-12-11 10:00

    The server will complete the request, unaware that the client has "moved on." The server will return the response to the client like it normally does. The client will simply ignore the response.

    So expect everything server-side to happen as normal, so the "fire and forget" method will work (since the client has moved on and has "forgotten"). But if you want to do anything client-side in response (which would negate the "forget" part) then there's no way for the new page to intercept the response. The browser will ignore it.

    0 讨论(0)
  • 2020-12-11 10:08

    The browser should kill the AJAX request, closing the connection to the server; however, this does not mean that your processing on the server is necessarily killed too: ignore_user_abort()

    0 讨论(0)
提交回复
热议问题