开发者

Wanting to have scrolling comments box pulling from mySQL using ajax

开发者 https://www.devze.com 2023-01-13 08:28 出处:网络
I haven\'t started on this yet because I\'m still pretty new, and I want to be sure there are not any issues with what I\'m wanting to accomplish.

I haven't started on this yet because I'm still pretty new, and I want to be sure there are not any issues with what I'm wanting to accomplish.

In it's simplest form, I want to have a div that will display a text quote that is pulled from a mySQL database. Every 5 seconds, the quote will fade out and the next will fade in.

Is ajax appropriate f开发者_JS百科or this? In more detail, I would have a few functions that would:

  • pull the first and last name of the user from the database
  • Convert that to initials: IE: Joe Smith would become -J.S.
  • Pull the place from the database: IE: Dallas, TX
  • Pull the quote from the database: IE: Great Job!

Then it'd populate the div (using a fade in) with

Dallas, TX:
"Great Job!"
-J.S.

My main question is is this a good way to do this? I don't want to use flash for this task. Is there a jQuery plugin that will accomplish this?

Thanks!


This should do the trick.
nb: '#comments' is a span INSIDE your comments div.
nb: 'comments.php' should return the content laid out as you wish it to be shown.
nb: the start param would be used in the limit statement on your db query.

function comments(ccount) {
  var ccount = (ccount == 'undefined' ? 1 : ccount);
  $.ajax({
    url: 'comments.php',
    data : {'start': ccount},
    success: function(data) {
      $('#comments').fadeOut('slow').html(data).fadeIn('slow');
    }
  });
  setTimeout(function(){comments(ccount+1)},5000);
}

then in your docment ready just have comments();

0

精彩评论

暂无评论...
验证码 换一张
取 消