views:

386

answers:

2

If I do an AJAX call, would the AJAX call be canceled if the user pressed "ESC" or leaved that page?

If the AJAX call gets canceled, would my PHP script continue to run until it finished what it was doing (provided time limit doesn't get reached or any other server configuration stops.), or would that process get killed at the same time as the Apache child it belongs to?

If the process does get killed with the Apache child even if it didn't finish, what would be the best way to keep that alive be or what other options should I consider? (ZendX_Console_Process_Unix not an option).

Thanks!

Later discoveries:

The AJAX call actually gets canceled if I hit "ESC" in Firefox (checked in firebug). The PHP process continues and is not affected by hitting ESC or closing the tab.

+2  A: 

If the server process starts before the user ends the ajax call (closing the window, or moving to another website) then it will be carried out until its final result. But an interrupted ajax call (meaning the transmission of data was not completed) the server will not process the call.

Note: hitting ESC will not end an ajax call per se, unless you javascripted that keypush behaviour.

pixeline
It does cancel the ajax call even if it's not scripted. Though the first part of your answer is true :)
Andrei Serdeliuc
A: 

One note... if you invoked your AJAX call from a hyperlink, using the href attribute, then YES, the user can press ESC and stop the transmission.

<a href="javascript:doFoo();">This can be canceled by pressing ESC</a>

<a href="#" onclick="doFoo();">This can NOT be canceled by pressing ESC</a>
scunliffe
The process gets canceled whichever way it's called. (tried with href, onclick and addEvent method via mootools.)
Andrei Serdeliuc
not sure how your test works, but I know for a fact that the onclick event can not be canceled by the user. I'll see if I can find a testcase to demonstrate.
scunliffe
hhm, I'm going to have to take that back... there are some other conditions needed that I didn't take into consideration.
scunliffe