microsocket Posted June 12, 2012 Posted June 12, 2012 Hi i have an ajax question and wondered if anyone could help...? I am using this below to call one line of text DB and refresh it as needed which all works fine .. <script> var auto_refresh = setInterval( function() { $('#loaddiv').fadeOut('fast').load('feed.php').fadeIn("slow"); }, 5000); </script> The problem is that t takes 5 seconds to call the first text so its blank for 5 seconds instead of starting instantly and having the 5 second delay between changing text... Does anyone know how to make it show instantly on first load without the 5 sec delay before it shows first text ?... Thanks Quote
lucky3809 Posted June 12, 2012 Posted June 12, 2012 5000 =5 seconds... change it to 1000 for 1 second. Quote
microsocket Posted June 12, 2012 Author Posted June 12, 2012 5000 =5 seconds... change it to 1000 for 1 second. I think you misunderstand what i am saying...I am aware the 5000 equals 5 seconds that is the delay time I want. What I am saying is the page I call the <div> on to refresh takes 5 seconds to load the first <div> content instead of instantly. The 5 sec delay is correct for changing the content as I want it...but I need to figure how to not have the 5 sec delay on first load. thanks Quote
HauntedDawg Posted June 13, 2012 Posted June 13, 2012 Do you perhaps have a demo online some where, where we can see it? Quote
microsocket Posted June 13, 2012 Author Posted June 13, 2012 no sorry its on local. All i need to figure out is how to stop the inital 5 sec delay before it shows first text. the feed page selects from a DB table randomly (there is around 20 entries in there of lines of text) and then displays that inside a <div></div> on another page. That aspect all works perfectly no issues at all. The problem is the 'first load' so to speak...when you go to the page that shows it it take 5 seconds delay before it shows the first line of text and i need to make that instant and then 5 seconds delay between changing. So the only thing i need to solve is how to make the first time it loads up not to have the 5 sec delay if that makes sense... Quote
HauntedDawg Posted June 13, 2012 Posted June 13, 2012 Since i can't predict your code. I'm assuming your using jQuery to initially show the "first load" page? Perhaps use direct php coding for initial page loading and have your div set to display: block;? Quote
Djkanna Posted June 13, 2012 Posted June 13, 2012 (edited) [JS] (function ($) { $('#loaddiv').load('feed.php'); var auto_refresh = setInterval ( function () { //Do your normal refresh stuff. }, 5000); })(jQuery); [/JS] Maybe? Or (Should satisfy the needs of the post below) [JS] ;(function ($) { $(function () { $('#loaddiv').load('feed.php'); var auto_refresh = setInterval ( function () { //Do your normal refresh stuff. }, 5000); }); })(jQuery);[/JS] Edited June 13, 2012 by Djkanna Quote
Spudinski Posted June 13, 2012 Posted June 13, 2012 (edited) My eyes, it burns... initDynContent = function() { $.ajax({ 'url': 'feed.php', 'success' : function(xhr) { $('#loaddiv').html(xhr.responseText); setTimeout(initDynContent, 5000); }, 'error' : function() { // do error handling } ); ); $(document).ready(initDynContent); Ok, I guess I should explain why everyone else is wrong... It just so happens that #loaddiv may not be on the DOM at time the functions are called, or jQuery hasn't been parses, thus rendering a undefined method/attr error. DOM elements should always be handled *after* the whole DOM has been loaded and rendered to the screen, except in extreme cases. Edited June 13, 2012 by Spudinski Quote
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.