user1914374
user1914374

Reputation: 1260

How to use ajax to navigate to multiple files

function disableHandler() {
    if (confirm("Are you sure you wish to Disable Penalty Marks?" + "\n" + "(You cannot change your option once you have confirmed)" + "\n")) {
        $.when($.ajax({
            url: "sessioncomplete.php",
            async: false,
            type: "POST"
        })).then(window.location = "complete.php");
        return true;
    }
}

In code above I use ajax in order to navigate to a page and then after the ajax has completed navigating to that page, it then re-locate to the complete.php session.

But I have never done this before but I realise I need a second page to be navigated through ajax before re-locating to the complete.php page. So I want the ajax to navigate to 2 pages penaltyinsert.php first then sessioncomplete.php and then re-locate to sessioncomplete.php.

My question is where and what is correct way of do I put the second ajax call?

Upvotes: 0

Views: 68

Answers (1)

bipen
bipen

Reputation: 36531

use ajax success function instead of $.when and then

$.ajax({
        url: "penaltyinsert.php",
        async: false,
        type: "POST",
        success:function(result){
            $.ajax({
                 url: "sessioncomplete.php",
                 async: false,
                 type: "POST",
                 success:function(response){
                      window.location = "complete.php"
                  };
               })
        };
    })

Upvotes: 1

Related Questions