How do I abort a long poll?
Hello!
I've got the following jquery code querying my server, but can't figure out how to Abort the query and reload the page immediately if someone clicks on <a> link.
Can anyone show me how to abort the current (all) ajax calls if someone clicks on <a> link????
Thanks,
regan
- function doPoll(url) {
- /* This requests the url "events.php". When it complete (or errors)*/
- $.ajax({
- type: "GET"
- ,url: url
- ,async: true /* If set to non-async, browser shows page as "Loading.."*/
- ,cache: false
- ,timeout: 50000 /* Timeout in ms (50seconds) */
- ,dataType: "script"
- ,success: function() { /* called when request to doPoll.php completes */
- setTimeout(
- function() {
- doPoll(url); /* Request next message */
- url = null; /* Prevent memory leaks */
- }
- ,1000 /* ..after 1 seconds */
- );
- }
- ,error: function(XMLHttpRequest, textStatus, errorThrown) {
- setTimeout(
- function(XMLHttpRequest, textStatus, errorThrown) {
- doPoll(url); /* Try again after.. */
- url = null; /* Prevent memory leaks */
- }
- ,15000 /* milliseconds (15seconds) */
- );
- }
- });
- };