How do I do two jquery-ajax processes at the same time?
I am trying to call 2 functions on the same page to send jquery-ajax at the same time to handle a delta task (function 1 is to make new records to the database, function 2 is to read the database every 5 seconds and then display records from the database in the table in html).
Before I go to function 1, the page works fine with a call to function 2 to read the records and display the records on the page every 5 seconds, but as soon as I call function 1 to enter new records, function 2 seems to be waiting in the queue and only run process after function 1. However, I'm pretty sure the problem is not because the database is locked, but function 1 is starting new records.
Does anyone know how I can handle jquery-ajax at the same time? See below for more details on 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 source to share
Have you checked the documentation: http://docs.jquery.com/Ajax/jQuery.ajax tried the asynchronous option? Another solution might be (albeit ugly) to copy the ord_process.php script and see if the problem is due to some internal queue or something else.
a source to share