Jquery $ .get (...) one at a time

I have a page with many actions on it that starts with $ .get, but I want to start all the triggers one at a time, not all at once, that is, a lot of loading time .. so what is the solution for me on this?

long before you give an answer .. I don’t want to run in time, I want to run after each request is completely executed from ajax, then go ahead and continue the cycle for ajax after the first completion.

+3
source share
4 answers

Do you want to execute synchronous queries? If so, you need to use the jQuery method ajaxinstead of getsetting async:false.

check out http://api.jquery.com/jQuery.ajax/

EDIT

As soon as one commenter correctly pointed out, the execution of synchronization requests freezes, only one javascript code of the stream. This means that the animation or other code does not work while you wait for the requests to finish.

An interesting option would be to “chain” your queries, execute the following query in a previous callback as follows:

$.get('ajax/first-call.html', function(data) {

  $.get('ajax/second-call.html', function(data){
    //etc
  }
});
+3
source

You can configure your own custom queue in jQuery.

http://api.jquery.com/queue/

  • Fill the turn with all the functions you want to perform.
  • - $.get().
  • $.get dequeue(), ajax.
+2

, ajax.

I used this plugin and it is quite simple.

+1
source

Most browsers will request four HTTP requests per domain at once. The rest will be queued and executed as standard. Thus, the browser is already performing some ordering on these requests.

0
source

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


All Articles