How do I abort a long poll?

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


  1. function doPoll(url) {

  2. /* This requests the url "events.php". When it complete (or errors)*/

  3. $.ajax({
  4. type: "GET"
  5. ,url: url
  6. ,async: true /* If set to non-async, browser shows page as "Loading.."*/
  7. ,cache: false
  8. ,timeout: 50000 /* Timeout in ms (50seconds) */
  9. ,dataType: "script"
  10. ,success: function() { /* called when request to doPoll.php completes */
  11. setTimeout(
  12. function() {
  13. doPoll(url); /* Request next message */
  14. url = null; /* Prevent memory leaks */
  15. }
  16. ,1000 /* ..after 1 seconds */
  17. );
  18. }
  19. ,error: function(XMLHttpRequest, textStatus, errorThrown) {
  20. setTimeout(
  21. function(XMLHttpRequest, textStatus, errorThrown) {
  22. doPoll(url); /* Try again after.. */
  23. url = null; /* Prevent memory leaks */
  24. }
  25. ,15000 /* milliseconds (15seconds) */
  26. );
  27. }
  28. });

  29. };