Reputation:
In javascript function I am submitin a form:
form.submit();
,
with huge amount of data.
Is it possible to cancel this operation beside clicking on browser's stop button?
UPDATE:
Maybe i didn't made my self clear i am submiting large files.
form with uploadcontrol that runs in iframe.
Upvotes: 0
Views: 921
Reputation: 36832
You could do something like what Gmail does: Undo Sending Mails (lab feature).
It justs delays the mail sending by a 5 seconds. If in that time the server receives a undo
AJAX call, the mail is not send.
This could potentially increase you serverside complexity, but not that much.
In the case that the information is not sent you could use this:
//IE
document.execCommand('Stop');
//Firefox
window.stop();
So the whole thing would look something like this (pseudocode):
stop_submit(current_id){
try{
document.execCommand('Stop');
}catch(e){}
try{
window.stop();
}catch(e){}
AJAXCall("/myfolder/cancel_submit/", "id="+current_id, "post");
return;
}
Upvotes: 3
Reputation: 41813
This is a classic problem with the client-server architecture. Once the HTTP request has been made, there is no stopping it. You will need a way to restore state after all requests to guarantee that everything is back to the way it was.
Now, you could do this with AJAX and use the abort
function. Or, you could try window.stop()
or document.execCommand("Stop")
, depending on your browser. But those do not solve the problem of the request having already been sent.
Upvotes: 0