The call is interrupted by page loading.

I am starting to use ajax and I always thought that it is completely asynchronous. But I found that the call may be interrupted by reloading the page or changing the page (for example, by clicking on the hyperlink). I got the impression that when I launch an ajax call, it runs regardless of what the browser does after that. It is not right?

Now for the specific problem that I have: think of an online test where users answer questions (by typing in text fields). When the text field loses focus, an ajax call is launched, which saves the value of the text field in the database. This works well when changing between text fields. However, I also have a submit button that calls the post action on another page (this is a submit button). When I enter something into the text box and click on the button after that, the call is not made. Moreover, when I enter a text field, click elsewhere (also initiating a call) and quickly press the submit button, the call will also not be completed. Is this expected behavior?

The reason I use ajax in the first place is to save the values, so when something unexpected happens, such as a browser crash, the already entered text is already saved.

Is my way of thinking wrong? How would you decide to solve this problem?

Thank you for your time!

+3
source share
2 answers

AJAX is asynchronous.

When you send an AJAX request, the javascript engine sends it and sets up a handler to respond.

, AJAX , , . ? Javascript , , .

, , .

: . . ajax , , .

Firebug, , AJAX , .

+2

- , javascript ajax , . , .

, . , , , , , .

: , .

, , .

, (.. 6 7), ()

+1

Source: https://habr.com/ru/post/1733964/


All Articles