0

新しいレコードがデータベースに追加されたときにのみアニメーション化されたテーブルを作成する方法。

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/ありがとう。

4

3 に答える 3

1
$.ajax({
 url : your_php_file.php',
 data : {data you'r going to send to server}, // example: data: {input:yourdata}
 success: function(response) {
     $('#table_id').append('<tr>'+response+'</tr>'); // response is the date you just inserted into db    
 } 
});

your_php_file.php:

add the item into db
echo that inserted data # if you echo, then you can catch this with ajax success function then you append it into your table. 
于 2013-06-03T10:18:20.133 に答える
1

以下のように記入してみてください。

$.ajax({
type: "post"
url : 'locationOfphpCode/phpCode.php',
data : {data you want to pass}, //{name: "dan"}
success: function(response) {
    // Only when successful animate the content
    newItem(response);
} 
});

PHP コードでは、ajax 呼び出しから渡されたデータを受け取る必要があります。

<?php
$name = $_POST['name'];
...
?>

PHPコードにいくつかの検証を追加できます。

これがあなたを助けることを願っています。

于 2013-06-03T10:22:08.773 に答える
0

あなたが与えた例は使用していますsetInterval(newitem, 2000)

そのため、一定の間隔で ajax 関数を呼び出す必要があります。

于 2013-06-03T10:16:54.917 に答える