N
Niall
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.setTimeout('abort_load()', 15000);
document.forms['resp_poll_form'].submit();
}
function abort_load() {
// um... what do we do here?
}
</script>
</head>
<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
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
Thanks in advance,
Niall
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.setTimeout('abort_load()', 15000);
document.forms['resp_poll_form'].submit();
}
function abort_load() {
// um... what do we do here?
}
</script>
</head>
<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
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