Program expect response requisicao ajax?

Asked

Viewed 165 times

0

Guys, I need to do several ajax requisicoes inside a loop and the program can only continue after the request is completed. I am using "async:false", but it hangs the whole page while waiting for the return. Does anyone know any way the code will continue only after the requisition is made?

for(i=0; i<10;i++)   
$.ajax({
        type: "GET",
        url: link,
        async: false,
        success: function (e) { 
          var items = e.items;                                                                                                                                                                                                      
          titulo = items[i].snippet.title; 
        }                           
    }); 
  • 2

    This makes no sense. Do you want to use AJAX to make synchronous requests? What’s the point of this?

  • 2

    I completely agree with Anderson, instead of seeing it this way he tries to change his line of reasoning regarding the elements of the form that need this return. How to assemble so that as you receive the answer by callback you can release the information to the user.Or post the form here with more details for ideas.

  • The problem is that the FOR loop cannot continue until the request is completed. That’s why every pass in the loop I fill a div with information fetched from the request and search for the position of the current value of i.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.