Jump to content
MakeWebGames

Quick Ajax query...


microsocket

Recommended Posts

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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...

Link to comment
Share on other sites

[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 by Djkanna
Link to comment
Share on other sites

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 by Spudinski
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...