title: $.ajax if condition
body: <p>I failed to write a condition inside of ajax by using the following syntax. </p>
  
  <pre><code>      var num = 1;
        $.ajax({
            type: "POST",
        //condition starts
          if (num === 1){
            url: url1,
            data: data1,
          }else{
            url: url2,
            data: data2,
          }
          //condition finishes
            success: success,
            dataType: dataType
          });
  </code></pre>
  
  <p>but this way works. </p>
  
  <pre><code> var num = 1;
  if(num === 1){
      $.ajax({
    type: "POST",
    url: url1,
    data: data1,
    success: success,
    dataType: dataType
  });
  }else{
      $.ajax({
    type: "POST",
    url: url2,
    data: data2,
    success: success,
    dataType: dataType
  });
  }
  </code></pre>
  
  <p>the 2nd method is not quite ideal as repeating my code. 
  is my first script in a wrong syntax? Could someone please point out? thanks</p>