im trying to load more data(like pagintaion) using jquery. my ajax is working, but jquery is not displaying the data the way i want it, this is my code,
jquery file:
$(function () {
//More Button
$('.more').live("click", function () {
var ID = $(this).attr("id");
if (ID) {
$("#more" + ID).html('<img src="moreajax.gif" />');
$.ajax({
type: "POST",
url: "ajax_more.php",
开发者_运维百科 data: "lastmsg=" + ID,
cache: false,
success: function (html) {
$("ul#statuses").append(html);
$("#more" + ID).remove();
}
});
}
else {
$(".morebox").html('The End');
}
return false;
});
});
this is the html file: this is the button thats clicked to retrieve more results!
echo'<div id="more'. $dateTime.'" class="morebox">
<a href="#" class="more" id="'.$dateTime.'">more</a>';
and finally the ajax_more.php file:
<?php session_start();
include("includes/connect.php");
include("includes/functions.php");
if(isset($_POST['lastmsg']))
{
$lastmsg=$_POST['lastmsg'];
$result="SELECT u.username, u.picture, m.id, m.user_note, m.reply_id, m.reply_name, m.recycle_id, m.recycle_name, m.dt
FROM relationships r, notes m, user u
WHERE m.user_id = r.leader
AND r.leader = u.user_id
AND r.listener =2
UNION
SELECT username, picture, id, user_note, reply_id, reply_name, recycle_id, recycle_name, dt
FROM user u, notes b
WHERE u.user_id = b.user_id
AND b.user_id =2
AND dt < '$lastmsg'
ORDER BY dt DESC
LIMIT 10 ";
$query= mysql_query($result) or die(mysql_error().$result);
while($row=mysql_fetch_array($query))
{
// echo the posts
echo formatUpdate($row['user_note'],$row['dt'],$row['picture'],$row['username'],$row['id'],$row['reply_id'],$row['reply_name'],$row['recycle_id'],$row['recycle_name']);
}
?>
<div id="more<?php echo $row['dt']; ?>" class="morebox">
<a href="#" id="<?php echo $row['dt']; ?>" class="more">more</a>
</div>
<?php
}
?>
P.S i checked firebug and ajax_more.php
is returning the results data back that i wanted, but on the frontend jquery is not showing it!!
When referencing classes with jQuery selectors (and CSS selectors) prepend the class name with a .
e.g., 'ul.statuses'
. When referencing ids use #
e.g., 'ul#statuses'
. Also it is best practice in jQuery to drop the tag in front of id selectors so if you reference an id in a selector it should look like this: '#statuses'
精彩评论