Daniel Smith
Daniel Smith

Reputation: 1734

Jquery - How to add conditions on $.When

On a page having two ajax call inside the $.when method. I wanted to make a thrid ajax call based on page-level variable values.

$.when(
     $.ajax({...}),
     $.ajax({...}),
.done(function (a, b) {
     ........
});

Something like this?

$.when(
     $.ajax({...}),
     if(typeof myvalue != "undefined"){ // condition here ?
       $.ajax({...}),
     }
.done(function (a, b) {
     ........
});

Upvotes: 0

Views: 53

Answers (1)

Barmar
Barmar

Reputation: 782785

Use a conditional expression:

$.when(
    $.ajax({...}),
    typeof myvalue != "undefined" ? $.ajax({...}) : null
).done(...)

Upvotes: 1

Related Questions