开发者

How to ensure a VERY delayed AJAX call is read properly

开发者 https://www.devze.com 2023-03-26 05:29 出处:网络
I have a File which process many other files and may take upto 30mins to process. I do an AJAX request to the file in the front end. The file outputs to another temporary file regarding the percentage

I have a File which process many other files and may take upto 30mins to process. I do an AJAX request to the file in the front end. The file outputs to another temporary file regarding the percentage of completion. And when it finishes it outputs a success message as its own XML output (not to the tmp file).

The problem i am having is, when the processing time is small .. say max upto 3mins, the AJAX request (made through jQuery) st开发者_运维百科ays alive. But a time out occurs when the processing takes longer time (above 4mins). And the AJAX connection is cut. How do i prevent it and make it stay alive till the browser is closed?


You won't be able to do that. Unless it is a comet server, that can keep the connection alive at the server side and when there is any update to the data, it pushes out the contents.

In your case, the only way i can think of is doing this:

function ajax_call () {
$.ajax({
  url : 'get_file_processing_output.html',
  success : function (response) {
     check your response, if file processing is not finished, then call ajax_call() again
     if it is finished, then just do whatever you need.
  },
  timeout : function () {
    time out then directly call ajax_call() again, maybe with a time interval would be better
  }
})
}

I have a success call back above in ajax, because i feel you should response something from your server side to tell the client that the processing is not yet done.

0

精彩评论

暂无评论...
验证码 换一张
取 消