Reputation: 73
I'm developing a website using PHP+Ajax. I have to fire a ajax request that may take long time to be processed (about 5 min), I do not need any response from this request so the user should be free to navigate into my website while the server is executing this ajax request in background.
My Code:
//I can easly lunch the ajax request
$.ajax({
type: 'GET',
url: "myurl.php",
async: true,
success: function (data) {}
});
this script works fine but as said it takes several minutes before finishing, and in this while the user cannot open any page of my domain. It looks like my browser is locked waiting for the response.
At the moment to "unlock" my browser i have the following solutions:
-restart my web server
-restart the browser
-wait until the script is done
Is there a trick or something fire "ghost" ajax requests?
(ghost means that i do not want to wait for the response)
I tryed to fire the request and than call the abort() function, but it abort all the request also the execution of the PHP script.
any tips?
PS. i tested it with Firefox 8, Chrome 15.0 and IE9
Upvotes: 0
Views: 301
Reputation: 10074
You could do different way, for ex. with simple queue:
This way user can navigate your site without problems, you can even provide progress to user how much is completed if you need it, by updating db during process.
Upvotes: 0
Reputation: 4143
If you are using sessions in your background script, you should call session_write_close
when you finish processing session vars, because a session cannot be open by more than one script at any given time.
Upvotes: 2