Note that there are some explanatory texts on larger screens.

plurals
  1. POClearInterval not working (but only sometimes) for sever api call
    primarykey
    data
    text
    <p>I have this function that is supposed to query the database every 4 seconds for any new content that may have been posted. I then take the return and refresh a feed with dynamic html made from whatever came back from the server. This all works great.</p> <p>My problem is that as part of the html there is a options tray that they can press that will slide over part of the content and give them different options to do with that content, delete, copy, comment stuff like that. Well when they pop out the tray I want to clear the interval timer so that it does not refresh the html on in the feed (making the tray go away). </p> <p>The other problem is that the user can have multiple trays open at the same time so I came up with this function to handle it all:</p> <pre><code>function setTimers(status) { var timerGetContent = null; if(status == "login") { tray_count = 0; timerGetContent = null; timerGetContent = setInterval(getContent,4000); alert("inside login"); } else if(status == "negitive") { tray_count--; if(tray_count == 0 &amp;&amp; timerGetContent == null) { timerGetContent = setInterval(getRecentContent,4000); alert("inside negitive"); } } else if(status == "positive") { tray_count++; clearInterval(timerGetContent); timerGetContent = null; alert("inside positive") } } </code></pre> <p>So when the user presses the button to pop out the tray it calls <code>setTimer</code> and passes it positive before it does anything else, and then when they press the button to close the tray it calls <code>setTimer</code> and passes it negitive. I know the calls work and that its being passed the right parameters, I even know that its going into the right part of the function depending on what is pressed but there are times when the interval is just not cleared and it keeps firing no matter what I do. Been working on this for hours and am totally stumped.</p> <p>Edit: I have tried to have the var <code>timerGetContent</code> outside of the function as a global variable. This had the same behavior problems.</p> <p>Edit2: Function that calls the <code>setTimers</code> function:</p> <pre><code>function slide_out(event) { clicked_element = document.getElementById(event.srcElement.id); var re_clicked = new RegExp(clicked_element.className, "g"); if(clicked_element.className == "options-bar slide-out") { BACKGROUND.setTimers("positive"); clicked_element.className = clicked_element.className.replace(re_clicked, ''); clicked_element.className += "options-bar slide-out open"; } else { clicked_element.className = clicked_element.className.replace(re_clicked, ''); clicked_element.className += "options-bar slide-out"; BACKGROUND.setTimers("negitive"); } </code></pre> <p>One other thing, the <code>setTimers</code> function is in the background file of the extension while this function is in the popup.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload