Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AJAX Call - What happens if the user leaves the page before the call is complete?

I have an app where I make an asynch AJAX call for each page that is loaded, so I can track the flow of a user through the app. Normally the call back to the server to record the visit happens very quickly. However, it appears that on occasion I'm missing some page visits, and I'm wondering if it's because they leave the page before the request is completed.

I know that an asynch AJAX is non-blocking. However, what I don't know is what happens to the AJAX request if the user leaves the page before the request is completed. Can someone help me with this?

If it matters, the service is a C# service.

like image 381
Randy Minder Avatar asked Oct 31 '22 15:10

Randy Minder


2 Answers

When a client leaves the page, AJAX calls will be aborted. The server will not be able to send a response to the client.

like image 77
Roemer Avatar answered Nov 09 '22 05:11

Roemer


If there is time to browser abort ajax request, request never arrives to server.
But once request arrived whether browser closed or not, it is processed by server

like image 42
asdf_enel_hak Avatar answered Nov 09 '22 03:11

asdf_enel_hak