Question: I want to check some user inputs with an `if statement` and depending on them, specify some parameters to send as an `ajax` request.

My approach doesn't work at all. It's just not valid code:

```
$.ajax({
    method : "GET",
    url : "test.php",
    data :
        if (...) {
            a: "abc",
            b: "def"
        }else{
            b: "ghi",
            c: "jkl"
        },
    success : function(data) {
        console.log(data)
    },
    error : function(data) {
        console.log(data);
    }
});

```

Does anybody have a better idea?

Answer: 
I think the cleanest way is to place your condition before the request call :

```
var data;

if (...) {
    data = {a: "abc",b: "def"};
}else{
    data = {b: "ghi",c: "jkl"};
}

$.ajax({
    method : "GET",
    url : "test.php",
    data : data,
    success : function(data) {
        console.log(data)
    },
    error : function(data) {
        console.log(data);
    }
});

```

Hope this helps.
You may use a self executing function to set data as: 

```
var i = true;
$.ajax({
  method: "GET",
  url: '/echo/js/',
  data: (function() {
    if (i)
      return { a: "abc", b: "def" }
    else
      return { b: "ghi", c: "jkl" }
  })(),
  complete: function(response) {
    console.log(response)
  },
  error: function() {
    console.log("Error")
  },
});

```