Padgoi Posted June 5, 2009 Share Posted June 5, 2009 Hi everyone. So I'm using this javascript slide down effect and it works fine and it's updating every 0.2 seconds (as the duration indicates) but it's updating constantly, not just when the last post is made. I only want it to slide-down when the last post is actually made, right now it's sliding down every 0.2 seconds regardless of whether a new post is made or not. I know it's the if statement I have wrong. Can someone help me out with this? Thanks in advance. Here's the code: var c=0 var t function ajaxLastPost() { var xmlhttp; if (window.XMLHttpRequest) { // code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp=new XMLHttpRequest(); } else if (window.ActiveXObject) { // code for IE6, IE5 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } else { alert("Your browser does not support XMLHTTP!"); } xmlhttp.onreadystatechange=function() { if(xmlhttp.readyState==4) { document.getElementById('DivLastPost').innerHTML=xmlhttp.responseText; Effect.SlideDown( 'DivLastPost', {duration: 0.1} ); } } xmlhttp.open("GET","sources/action_public/lastpost.php",true); xmlhttp.send(null); c=c+1; t = setTimeout("ajaxLastPost()",5000); } Quote Link to comment Share on other sites More sharing options...
Padgoi Posted June 6, 2009 Author Share Posted June 6, 2009 Anyone help please? Quote Link to comment Share on other sites More sharing options...
Axeia Posted June 6, 2009 Share Posted June 6, 2009 I'm guessing you'd need to compare the result you're getting to that of what's currently in there. something like: if(xmlhttp.readyState==4) { //Only slide down if something actually changed. if( xmlhttp.responseText != document.getElementById('DivLastPost').innerHTML ) { document.getElementById('DivLastPost').innerHTML=xmlhttp.responseText; Effect.SlideDown( 'DivLastPost', {duration: 0.1} ); } } edit thinking about that again it doesn't make much sense , if( xmlhttp.responseText != document.getElementById('DivLastPost').innerHTML ) that bit needs to be compared to the last result on the currentpage, prolly some value you want to set when the page loads. Quote Link to comment Share on other sites More sharing options...
Padgoi Posted June 6, 2009 Author Share Posted June 6, 2009 Thanks Axela but that didn't seem to fix the issue, same issue persists. Quote Link to comment Share on other sites More sharing options...
Ken2k7 Posted June 7, 2009 Share Posted June 7, 2009 I don't know what Effect.SlideDown() does. I assume it doesn't have a continuous effect, right? And why did you put a setTimeout in the ajaxLastPost function to call itself? That would just keep running indefinitely. You probably want to make an if statement to check if the last post is submitted (not sure how you do that) and if so, run the AJAX stuff. If not, don't. Quote Link to comment Share on other sites More sharing options...
Padgoi Posted June 8, 2009 Author Share Posted June 8, 2009 Thanks ken, but I really don't know javascript well enough to know how to call the last post submitted and the script worked fine (didn't continuously update) before I added the slidedown effect. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.