#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2013
    Posts
    3
    Rep Power
    0

    Prevent one cycle of periodic script?


    I would like a PeriodicalExecuter script to test whether the user has posted the current page, before it runs. If the user has posted, the executer should not run. There are about 50 buttons on the page with which the user can perform a post action (submit buttons or image buttons that act as tabs to other pages).

    Is this possible?

    Thank you
  2. #2
  3. A Not To Shabby Code Smurf
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Aug 2008
    Posts
    1,131
    Rep Power
    119
    I have never used a PeriodicalExecuter, but I would assume you could create a HTML5 sessionStorage() (once one of your buttons have been clicked/submited... or whatever your going for here); then validate whether the session exist or not. If it does not exist, then set your PeriodicalExecuter up to run; otherwise if the session exist... do not let it run. That's probably how I would go about do this. Alternatively, you could just do this server side and send sessions data to your page and validate, to submit or not, where necessary.
  4. #3
  5. No Profile Picture
    Permanently Banned
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2013
    Posts
    5
    Rep Power
    0

    Nice


    THanks for sharing a brilliant javascript coding
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2013
    Posts
    3
    Rep Power
    0
    Hi, I looked at the w3c proposal but am a little thickheaded. Would I write to this storage space on loading each page? Does it get automatically deleted when the user clicks on an image button (a tab image in my case), or on a submit button?

    What seems to be happening is if the PeriodicalExecuter happens to fire just as the user has clicked to post the page, an AJAX get (in the PeriodicalExecuter) truncates some of the information being posted by the user. So there's some timing problem with the two calls.

    Thanks for responding.
  8. #5
  9. A Not To Shabby Code Smurf
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Aug 2008
    Posts
    1,131
    Rep Power
    119
    Originally Posted by DJL94131
    Hi, I looked at the w3c proposal but am a little thickheaded. Would I write to this storage space on loading each page? Does it get automatically deleted when the user clicks on an image button (a tab image in my case), or on a submit button?
    You would declare the storage, based on when someone clicks one of your buttons. That was your goal... right; to prevent the PeriodicalExecuter from running, once a button has been clicked? The sessionStorage variable will delete itself; once your web page's / website's browser session expires. That is to say; once the tab/page/browser has been closed. This will terminate the session and the next time the same visitor comes back, to your button page; they will start fresh..., without any session data and... that means that the PeriodicalExecuter would run again; until another button was clicked.

    A few examples...

    http://davidwalsh.name/html5-storage
    https://developer.mozilla.org/en-US/...de/DOM/Storage
    http://www.html5rocks.com/en/features/storage
  10. #6
  11. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2013
    Posts
    3
    Rep Power
    0
    I added a listener under document.observe when the page loads,

    Code:
    document.observe("dom:loaded", function() {
       ...
       if(window.sessionStorage) {
          sessionStorage.setItem(pageType, "");  // initially blank value this page
          document.observe('click', function(event) {
             if((event.findElement('input[type=submit]')) || (event.findElement('input[type=image]'))) {
                sessionStorage.setItem(pageType, "posted");
             }
          });
       }
       new PeriodicalExecuter(function(pe) {msgEntryRqst(host_URL, web_sid, pageType, recordNbr);}
       ...
    Then when the PeriodicalExecuter fires its method, I test for the presence of "posted" for this particular page (pageType is a hidden field named "c", with a unique value for each page).

    Code:
    ... 
    var cmd = document.getElementsByName("c")[0]; // only one item NAMED "c" (command) on pg; cmd.value is same as pageType, from above
    var proceed_B = false;
    if(window.sessionStorage) {
       if(cmd.value) {
          if((sessionStorage.getItem(cmd.value)) && (sessionStorage.getItem(cmd.value) == "posted")) {  
             // in this case do not proceed, active user post underway
          } else {
             proceed_B = true;
          }
        }
    } else {  // no session storage support
       proceed_B = true;
    }
    if(proceed_B) { 
      // proceed with AJAX call
    ...
    I did some testing on a "live" server this morning, and I haven't observed the truncation problem when the AJAX call fires simultaneously with the user submit. I need to watch it for a couple of days (especially because there are no users on it right now, so I need to check it under load). But this change may have solved the problem.

    Thanks for your help, web_loone!

IMN logo majestic logo threadwatch logo seochat tools logo