Richard77
Richard77

Reputation: 21641

How can I make a second AJAX request inside the first AJAX's success method?

Let's say I have this ajax call. I'm requesting a json object that contains 2 strings. If the first one is not empty, I will display a confirmation popup to warn user and to get is decision whether to proceed.

If the user decides to request the file, then the second string contains the path to the file.

So how can I make a second AJAX request inside the first AJAX's success method?

function reqQuote(_url)
{
   $.ajax({
      url: _url,
      success: function(data){
          if(data.itemsNotSupportedWarning != null){

         var r = Confirm('The template doesn\'t support the following languages: ' 
                         + data.itemsNotSupportedWarning + 
                         + ' Would you like to continue?');
            if(r == true)
            {
               //request the template file ...
            }
          }
          else{
             //there is no warning, i.e. just go ahead and request the template file.
         }
      }
  });
}

Thanks for helping.

Upvotes: 0

Views: 701

Answers (2)

Rajeshkumar
Rajeshkumar

Reputation: 895

Inside the success method of the ajax call call some othe javascript methods where you can call ajax like normal ajax. See below.

    function reqQuote(_url)
    {
       $.ajax({
          url: _url,
          success: function(data){
                        testMethod();
      }
  });
}

function testMethod(){
    //Ajax Code Here
    }

Upvotes: 1

konghou
konghou

Reputation: 557

Simply put another $.ajax(...) inside if(r == true) { ... } and define another success callback function for it.

Upvotes: 2

Related Questions