Ben
Ben

Reputation: 11208

How to run an ajaxcall after another completes?

Just wondering, in my opinion the code below is able to run a second ajaxfunction when the first one completes.

if(xmlHttp) // xmlHttp is an XMLHttpRequest object
  {
    xmlHttp.onreadystatechange = function()
    {
      if(xmlHttp.readyState == 4 && xmlHttp.status == 200)
      {
         // second call can be made here because a first one is ready?
      }
   }

Am I correct on this? Or do I misunderstand the thing I want to achieve?

Upvotes: 1

Views: 73

Answers (1)

hvgotcodes
hvgotcodes

Reputation: 120318

yes you can do that, but it might be better to call a function that does your second request flow.

Upvotes: 1

Related Questions