【发布时间】:2013-06-03 09:58:54
【问题描述】:
如何使动画表格仅在将新记录添加到数据库时才动画。
Ajax/Js(在 index.php 中):
$.ajax({
url : 'Not sure what goes here?',
data : {Not sure what goes here?},
dataType : 'application/json', // Is this correct?
success: function(response) {
// Only when successful animate the content
newItem(response);
}
});
var newitem = function(response){
var item = $('<div>')
.addClass('item')
.css('display','none')
.text(response)
.prependTo('#scroller')
.slideDown();
$('#scroller .item:last').animate({height:'0px'},function(){
$(this).remove();
});
}
我的 php (latest.php):
include ('db.php');
$sql2 = "SELECT * FROM `feed` ORDER BY `timez` DESC";
$res2 = mysql_query($sql2) or die(mysql_error());
while($row3 = mysql_fetch_assoc($res2)){
$user = $row3['username1'];
$action = $row3['action'];
$user2 = $row3['username2'];
echo ''.$user.''.$action.''.$user2.'<br>'; // Needs to be a json array?
我无法让它工作,这是表格的运作方式http://jsfiddle.net/8ND53/ 谢谢。
【问题讨论】:
-
您的代码中的什么不工作,您有什么问题?
-
我不知道如何安排它我不擅长ajax它不会从latest.php页面获取任何数据。
-
我想传递什么 "echo ''.$user.''.$action.''.$user2.'
';"返回。例如:user1 喜欢 User2 User4 不喜欢 User1 我希望表格显示最新的用户活动。 -
你想传递什么数据给php? URL后写下php代码的位置
-
你检查过 jquery.com/ajax 吗?有很多例子可以回答你真正的基本问题。
标签: php javascript sql ajax json