Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > Aborting an ongoing Javascript form submission.

Thread Tools

Aborting an ongoing Javascript form submission.

Posts: n/a
The short version: how does one get Javascript to abort a form
submission/page load half way through?

Long version:

I have a page, the guts of which can be summarised as:

function poll_response() {
// do a bunch of dhtml taking the contents of a cookie and inserting
them into a div.

window.setTimeout('abort_load()', 15000);


function abort_load() {
// um... what do we do here?
<body onLoad="poll_response(); setInterval('poll_response()', 1000);">
<form name="resp_poll_form" action="/" method="POST">
<!-- and so on... -->

The (php) script that the form posts to puts information into the
relevant cookie and sends an HTTP 204 response, so the actual page is

Under ideal conditions, this means that the script will poll the server
once per second, adding any new information to the page without
actually reloading the page.

However, occasionally the server will be unavailable. If the browser is
allowed to continue attempting to read the response, it will eventually
time out and stop the script. This is not the desired result; the
browser should keep trying until the server becomes available again
(which it always does, after a minute or so).

Hence the setTimeout() call. The idea is that after 15 seconds of not
hearing anything back from the server, the browser stops attempting the
current transfer, and tries a new one.

The problem is, I have no idea how to achieve this end. I was initally
under the impression that the abort() function would, in Internet
Explorer at least, cause any current data transfers to stop. As it
turns out this isn't exactly the case: IE throws an error when it
reaches that line, which *does* have the effect of stopping the
transfer and allowing a new one to start, but it's not exactly clean.
Firefox throws an error as well, but it also doesn't run any more
scripts, so it doesn't work at all.

So how does one cause the transfer to stop?

I need solutions for this problem which will work in Internet Explorer
>= 6.0 and Firefox >= 1.5. (Preferrably the *same* solution, but I don't hold out much hope...) Can anyone help?

Thanks in advance,


Reply With Quote
Erwin Moller
Posts: n/a
Niall wrote:

> The short version: how does one get Javascript to abort a form
> submission/page load half way through?

Sorry, I ahve been so bold not to read the whole question, but this can
Start your page (in HEAD) with
var pageLoaded = false;

And at the very end of the page:
var pageLoaded = true;

Add to the form:
<form .... onSubmit="return pageLoaded;">

If onSubmit returns false, the form is not submitted, if true it is

Hope that helps.

Erwin Moller
Reply With Quote
Posts: n/a

Erwin Moller wrote:

> Sorry, I ahve been so bold not to read the whole question

You should have; the answer you gave is unrelated to the question.

Reply With Quote
Posts: n/a

Niall wrote:
> The short version: how does one get Javascript to abort a form
> submission/page load half way through?

Long sad answer (but see the happy one at the bottom): you can't. Start
of form submission means end of the current page existence. Despite
"orphan script" may remain in the execution stack for some time, its
usage would be the last option to choose for a reliable solution.

Morover you have only partial control over UA timeout: it has its own
period in seconds defined in system settings (10sec - 60sec regularly)
so you can abort earlier - but not later.

Short happy answer: there is IXMLHTTPRequest/XMLHttpRequest technique
and that will work for you. See for instance

Reply With Quote

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Any serious attempts at ruby-to-javascript converters ongoing? Kenneth McDonald Ruby 1 10-22-2008 01:17 AM
Ongoing Vonage problems Boborann VOIP 13 08-31-2007 08:45 PM
device drivers error MS screen says sorry........xp crashing ongoing =?Utf-8?B?REo=?= Microsoft Certification 0 04-16-2004 04:26 PM
PIX 515 drops ongoing VPN sessions Nicklas Cisco 0 11-24-2003 10:57 PM
Ongoing Bios Password Problem for Sony Vaio FX Series Treb Computer Support 5 11-24-2003 02:35 PM