473,569 Members | 2,573 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Aborting an ongoing Javascript form submission.

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:
<script>
function poll_response() {
// do a bunch of dhtml taking the contents of a cookie and inserting
them into a div.

window.setTimeo ut('abort_load( )', 15000);

document.forms['resp_poll_form '].submit();
}

function abort_load() {
// um... what do we do here?
}
</script>
</head>
<body onLoad="poll_re sponse(); setInterval('po ll_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
undisturbed.

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,

Niall

Nov 7 '06 #1
3 2120
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
help:
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="retur n pageLoaded;">

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

Hope that helps.

Regards,
Erwin Moller
Nov 7 '06 #2

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.

Nov 9 '06 #3
VK

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
<http://www.ajaxtoolbox .com>

Nov 9 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
3009
by: Prometheus Research | last post by:
http://newyork.craigslist.org/eng/34043771.html We need a JavaScript component which will auto-submit a form after a set period has elapsed. The component must display a counter that dynamically shows the minutes and seconds remaining before submission. We have a fairly tight deadline (by 5PM EST, Friday, June 25); we are using a "bounty"...
10
6062
by: ljlolel | last post by:
So.. I have a form that submits to an ASP.net site made in C-sharp. The ASP site is not mine, i do not have the server side code. When I submit from my form by pressing the Submit button, I get different results than when I use a javascript submit: form1.submit();. I think the javascript submit is working as it should, since I want the...
12
3104
by: googlegroups | last post by:
Hi, I'm making a javascript program for rolling dice for a roleplaying game that's played in a forum. The die roll gets generated, gets stored as text in a hidden form field, and then gets written to the mySQL database upon form submission. What I want to do is prevent cheaters from being able to create their own die roll, and the best way...
3
2401
Plater
by: Plater | last post by:
I am having a spot of trouble with a little situation. I want to make the submit invisible on a submit so that the user cannot keep clicking on it while the server is receiving the file transfer. The webpage will change after the submission, so un-hiding of the button should not be an issuse. Or so I thought. Given a rough puesdo code of: ...
0
7924
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8130
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7677
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7979
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6284
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5219
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
1
2115
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1223
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
940
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.