tags:

views:

319

answers:

1

I trying to call 2 functions in the same page to submit jquery-ajax at the same time to process difference task (function 1 is to instert new records into the database, function 2 is to read the database every 5 sec then display the records from the database on the table in html).

Before I call to function 1, the page working fine with calling to function 2 to read records and display records on the page by every 5 sec, but once I call to function 1 to instert new records, function 2 seem like waiting on the queue and only start process after function 1 compliant. However, I pretty sure this problem is not because of the database been lock while function 1 insterting new records.

Does anyone know how can I make both jquery-ajax processing at the same time? Please see below for more details of my code:

HTML:

<table style='width:100%' border="0">
    <tr>
        <td width="120"><input onclick="submitAction()" type="button" value="Process"></td>
    </tr>
</table>

<script>
    var myInterval = setInterval('getUpdatedRecord()', 5000);
</script>

Javascript:

function submitAction()
{
    var paramList = "Action=make_process";

    ajaxRequest = $.ajax({
        url: "ord_process.php",
        type: 'POST',
        data: paramList,
        error: function(){
             msgObj.innerHTML = '<div style="width:313px; padding-top:40px;"><p class="cAlign">Connecton error.<br>Please try again.</p></div>';
          },
        success: function(data){
      var endDateTime = getCurrentDateTime();
      msgObj.innerHTML = ''; 
     alert("  "+data+"\n\n  Start Date&Time : "+startDateTime+"\n    End Date&Time : "+endDateTime)
         } 
     });    
}



function getUpdatedJobRecord()
{
    var paramList = "Action=get_job_record&call=ajax";

    ajaxRequest = $.ajax({
         url: "ord_process.php",
         type: 'POST',
         data: paramList,
         error: function(){
          msgObjB.innerHTML = update_date;
             msgObjA.innerHTML = '<td><div style="width:313px; padding-top:40px;"><p class="cAlign">Connecton error.<br>Please try again.</p></div></td>';
         },
         success: function(data){
          msgObjB.innerHTML = update_date;
          msgObjA.innerHTML = data;
         }  
    }); 
}
A: 

Have you checked the documentation: http://docs.jquery.com/Ajax/jQuery.ajax tried the async-option? Another solution could be (although it is ugly) to copy the ord_process.php script and see if the problem is because of some internal queue or something.

Daniel Persson