SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Wizard silver trophybronze trophy
    Join Date
    Jul 2008
    Location
    New York, NY
    Posts
    1,432
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    JavaScript Polling Issue

    Hi All,

    I come to you in need of help. If anyone could help me out, I'd greatly appreciate it.

    Problem:
    When I click "End", it doesn't destroy (lack of a better word) the setTimeout function.
    You'll notice the json file is called, at some point 6 times

    Note:
    I left a console.log in the code to show you the issue I speak of (so ensure you have your console open).

    Requirements:
    By default the json file should load once, then upon clicking "Start", the json file needs to be called (every x secs) until "End" is clicked (in which case the polling will stop).
    Last edited by Pullo; Apr 11, 2014 at 00:07. Reason: Removed URL

  2. #2
    Under Construction silver trophybronze trophy AussieJohn's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    776
    Mentioned
    11 Post(s)
    Tagged
    0 Thread(s)
    I just had a quick look at your example page and everything seemed to work just fine. Are you still having an issue?

    If you're talking about the number that's returned by console.log(_this.setPolling), that's the ID of the setTimeOut not the # of times it's been called.
    var details = {
    . . web: "afterlight.com.au",
    . . photos: "jvdl.id.au",
    . . psa: "usethelatestversion.com"
    }

  3. #3
    SitePoint Wizard silver trophybronze trophy
    Join Date
    Jul 2008
    Location
    New York, NY
    Posts
    1,432
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    Thanks for the quick response (that's good to know). If you click "Start" & "End" a few times, you'll see the number of requests (json) double, if not triple. Let me know if you can't replicate the issue. Keep clicking a few times and you'll see.

    Thanks again for your expertise.

  4. #4
    Under Construction silver trophybronze trophy AussieJohn's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    776
    Mentioned
    11 Post(s)
    Tagged
    0 Thread(s)
    Ah, I see. It looks as if it's starting the polling setTimeOut multiple times.

    I think the most straightforward way to get around that is to check if _this.setPolling is defined.

    In addition to this, you will want to delete the reference to the timeout once it's been cleared, i.e.
    Code JavaScript:
    window.clearTimeout(_this.setPolling);
    delete _this.setPolling;
    Last edited by AussieJohn; Dec 3, 2011 at 23:58. Reason: removed crappy stuff from RTE pasting
    var details = {
    . . web: "afterlight.com.au",
    . . photos: "jvdl.id.au",
    . . psa: "usethelatestversion.com"
    }

  5. #5
    SitePoint Wizard silver trophybronze trophy
    Join Date
    Jul 2008
    Location
    New York, NY
    Posts
    1,432
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It's now working:
    http://coopersemantics.com/code/poller.html

    Thanks for your help man

  6. #6
    Under Construction silver trophybronze trophy AussieJohn's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    776
    Mentioned
    11 Post(s)
    Tagged
    0 Thread(s)
    Awesome.

    No worries dude, glad to be able to help
    var details = {
    . . web: "afterlight.com.au",
    . . photos: "jvdl.id.au",
    . . psa: "usethelatestversion.com"
    }


Bookmarks

Posting Permissions

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