我有一个javascript动画表我希望这可以从另一个页面获取内容,并在将新记录添加到数据库时进行更新。
的javascript:
var newitem = function(){
var item = $('<div>')
.addClass('item')
.css('display','none')
.text('content.php') -- Get the content somehow?
.prependTo('#scroller')
.slideDown();
$('#scroller .item:last').animate({height:'0px'},function(){
$(this).remove();
});
}
setInterval(newitem, 2000);
content.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.'';
示例(http://jsfiddle.net/8ND53/)如何使用我的php进行此操作并使javascript只有动画并在新内容添加到数据库时更新?
答案 0 :(得分:0)
您需要使用 Ajax
$.ajax({
url : 'your data point in php',
data : {data you want to send},
dataType : 'application/json',
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();
});
}