title: my two ajax send request at the same time
body: <p>I have a problem about my code. In my program, I have here an option box that will allow the user to choose what page did she/he want to show in my <code>tblPlank</code> and <code>tblSummary</code> (tblSummary and tblPlank were both jqgrid). Evrytime he chooses a page and click a button, it will call the function <code>displayPageNum</code>. Now, my problem is, this two:</p>
  
  <p><code>url:'processjson.php?path=' + encodeURI('getData/tally/page') + '&amp;json=' + encodeURI(JSON.stringify(datas)),</code> </p>
  
  <p>and </p>
  
  <p><code>url:'processjson.php?path=' + encodeURI('getReport/tallySummary') + '&amp;json=' + encodeURI(JSON.stringify(datas)),</code>, </p>
  
  <p>send request at the same time which sometimes makes my other table (or the other) dont display the right output. So how can I fix this to make it send request one at a time?</p>
  
  <pre><code>function displayPageNum(){  
   var flag = 0;
    if ($("#page option:selected").text() != 'all'){    
      var datas = {
        "SessionID": $.cookie("SessionID"),
        "dataType":"data",
        "transaction_id":$('.transactionID').attr('id'),
        "page":$("#page option:selected").text()
      };
      $('#tblPlank').setGridParam({
      url:'processjson.php?path=' + encodeURI('getData/tally/page') + '&amp;json=' + encodeURI(JSON.stringify(datas)), 
        datatype: primeSettings.ajaxDataType
      });
      $('#tblPlank').trigger('reloadGrid');     
      flag =1;
      if (flag == 1){
        var datas = {
          "SessionID": $.cookie("SessionID"),
          "dataType":"data",
          "transaction_num":$('.transactionID').val(),
          "page":$("#page option:selected").text()
        };
         $('#tblSummary').setGridParam({
          url:'processjson.php?path=' + encodeURI('getReport/tallySummary') + '&amp;json=' + encodeURI(JSON.stringify(datas)), 
          datatype: primeSettings.ajaxDataType      
        });             
        $('#tblSummary').trigger('reloadGrid');
      }
    }
   }
  </code></pre>
  
  <p>I put the flag variable just to make send the request one at a time, but still sending request at the same time.</p>