0

I need to make several ajax call consequentially, e.g., request #2 should be made only after successfully finished request #1. We can make it in jQuery as mentioned here How to handle several ajax requests? But is there any way to do it in vanilla javascript?

Alex
  • 634
  • 1
  • 8
  • 29
  • You can use [Promise](https://github.com/then/promise) library separately for organizing your AJAX calls. – raina77ow Mar 28 '14 at 22:31
  • This answer has vanilla javascript to make an ajax call. http://stackoverflow.com/questions/2557247/easiest-way-to-retrieve-cross-browser-xmlhttprequest – MarkHoward02 Mar 28 '14 at 22:51

1 Answers1

0

Use a callback function.

Quoted from: http://www.w3schools.com/ajax/ajax_callback.asp

xmlhttp.onreadystatechange=function()
{
     if (xmlhttp.readyState==4 && xmlhttp.status==200)
  {
     document.getElementById("myDiv").innerHTML=xmlhttp.responseText;
  }
} 
Aboba
  • 316
  • 1
  • 10