📜 ⬆️ ⬇️

Suggest on Google - no Ajax

Honestly, I have long had the impression that if the client (in this case, the browser) needs to take something from the server without reloading the page, then it must be AJAX XMLHttpRequest. A user poked somewhere, an event worked, an AJAX XMLHttpRequest request was generated, a response came from the server, the callback processed it and the user saw something.

But there is a problem. If the user quickly and often presses on the keys, a number of parallel requests are created and as a result, the request sent later may work much earlier than the earlier request, which will result in incorrect data being output.


')
Yes, it is possible to be confused, to think up how to extinguish early requests or to do turns. Or something else.

I liked Google’s decision on this topic:

image

Those. each time a button is pressed in the search field, the entered text is inserted into the URL of the JS-file to be connected, a JS-array with data is generated on the server, depending on the file parameters entered, and the function of the results is called at the end.

No AJAX XMLHttpRequest requests, everything is simple and smart.

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


All Articles