开发者

How to get Ajax Request Progress?

开发者 https://www.devze.com 2023-01-18 10:07 出处:网络
  I am developing a project which is built in CakePHP and using jQuery in it. I have a script which need to be called by an ajax request. This request do many manipulation in database and ta

  I am developing a project which is built in CakePHP and using jQuery in it. I have a script which need to be called by an ajax request. This request do many manipulation in database and takes too much time. Between the execution it is writing its status in a seperate file so i can see the status of script execution. Every time it open the file write in it the status of execution and then close the file, to remove the problem of file lock.

    Now When this script is in progress I am sending another ajax request which just read that file and get the content back periodically after every 20 seconds. Now the problem is when first ajax request is busy with mysql, any other request to server will be on halt. Mysql creating processes of all these requests and put this request in sleep mode. I think its due to framework, c开发者_运维问答ause on every request framework need to check the database. When the first main script completed all other request are also get completed.

   Is there any way that i can get the ajax progress ?? Correct me if I am wrong somewhere...!!! Thanks in advance.


If you are using jQuery for your Ajax needs you might want to look at the "async" option of the $.ajax method. The way i see it you want to show progress per the request currently being worked on. Now , this has a downside, it will lock whatever else you are doing but it will be showing correctly the progress of each "thread". I am not familiar with Cake, since i use Kohana. Now, mysql putting something to "sleep" is quite unlikely, it rather queues them. There is no real "progress" here, I would suggest to use something like $.ajaxStart or $.ajaxStop ( whatever that was called in jquery ) , as soon as you get a response back from the server you can hide the progress element.


I did it. I just need to call the script which read the file and send back the data from a seperate php file. No need to call the framework...!!!

0

精彩评论

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