I have a form with certain action. When the form is submitted I send an ajax call that calls this action. In the otherhand, I am sending another ajax call to update the progress. I have done it as follows:
$("form").submit(function() {
function callBack()
{
if( (this.readyState == 4) && (this.status == 200) )
{
console.log(this.responseText);
}
}
function updateProgress (){
asyncReq('/get_progress?progress='+progress, callBack);
}
function asyncReq(url, functionCallBack)
{
var request; //request must be a local var to avoid race condition
try
{ //for modern browsers
request = new XMLHttpRequest;
}
catch (err)
{// legacy IE
request = new ActiveXObject("Microsoft.XMLHTTP");
}
request.onreadystatechange = callBack;
request.open("GET", url, true);
request.send();
};
var progress = $("#progress").val();
asyncReq('/get_progress?progress='+progress, callBack);
setTimeout(updateProgress, 2000);
$(this).ajaxSubmit({async: true});
return false;
});
I have 2 asynchronous javascript calls here, one for submitting the form and one for updating the progress. When I print out the responseText
in callBack
, I can only see 0.0 and 1.0. That is one before the ajaxSubmit()
is called and after it is finished. I would like to get all the value of the progress in the middle as well. As far as I understand, the 2nd ajax call for asyncReq
is called only after the ajaxSubmit
is finished. Can anyone give me any idea about how I make the another complete ajax call before the ajaxSubmit()
is complete?
Note:
The form consists of file field and ajaxSubmit
unzips, processes the file and updates the progress table after each file is processed. The get_progress
method extracts the progress value of that table. I am using jquery.form.js for submitting the form by ajax call.