Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    May 2012
    Posts
    89
    Thanks
    51
    Thanked 0 Times in 0 Posts

    Cancel current AJAX process?

    Gidday

    Until I learn how to set up a comet server, I am using basic 5 second polling to get updates for the social networking part of my site.

    What I'd like to know is if a 5 second poll is in progress (using a basic setInterval function), and there is a network/server problem that slows things down returning from php (to the point where is takes longer than 5 seconds to return), how do I tell AJAX NOT to send another poll until the current one is complete?

    Thanks

  • #2
    Senior Coder Dormilich's Avatar
    Join Date
    Jan 2010
    Location
    Behind the Wall
    Posts
    3,240
    Thanks
    12
    Thanked 340 Times in 336 Posts
    I see two principal ways to solve that.

    - start a new poll 5 seconds after the last one returns. you would use recursion here (setTimeout())

    - before sending a new poll, check that the old one is already done (via XmlHttpRequest.readyState)
    The computer is always right. The computer is always right. The computer is always right. Take it from someone who has programmed for over ten years: not once has the computational mechanism of the machine malfunctioned.
    André Behrens, NY Times Software Developer

  • Users who have thanked Dormilich for this post:

    shaunthomson (07-30-2012)

  • #3
    New Coder
    Join Date
    May 2012
    Posts
    89
    Thanks
    51
    Thanked 0 Times in 0 Posts
    Thanks Dormilich - I'll start learning those AJAX processes.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •