.load()加载页面更改时

时间:2012-06-06 00:20:31

标签: php jquery ajax

这是我的问题 - 我有Div包含“file.php”与数据库的内容然后我将新数据插入数据库,并希望重新加载.load()file.php到div但内容是相同的,直到我刷新页。有谁知道它是什么? File.php

<?php
include "../lib/dbconnect.php";
$class = $_GET['class'];
$get_posts = mysql_query("SELECT content, date, author, author_id FROM classPosts WHERE class = '$class' ORDER BY id DESC");
while (list($content, $time, $author, $author_id) = mysql_fetch_row($get_posts)){
    $get_user_name = mysql_query("SELECT name, lastName FROM users WHERE nick = '$author'");
    while (list($name, $lastName) = mysql_fetch_row($get_user_name)){
        $time = new Cokidoo_DateTime("@" . $time);
        echo "
            <div class=\"div\">
            <div class=crop-small title=\"$author\">
                <a href=/user/user.php?user=$author_id><img src=/user/pics/$author_id.jpg class=img-small></a>
            </div>
            <span class=small-text><b style=\"color: rgb(100,100,100)\">$name $lastName</b><br>
            <span class=\"small-text\">Přezdívka <b style=\"color: rgb(100,100,100)\">$author</b></span><br>
            Přidáno $time</span><p><br></p>
            <span class=\"small-text\">$content</span>
            </div>
        ";
    }
}

&GT;

有Javascript

 if(data.success)
            {
                $("#class_posts").fadeOut(function(){
                   $("#new_post").hide(0);
                 $("#class_posts").load("../trida/get_posts.php");
                   $("#class_posts").fadeIn();
                   $("#new_post_text").html("");
                });
            }

1 个答案:

答案 0 :(得分:2)

尝试在结尾附加一个随机数作为查询字符串 - 以防止缓存。

var randNum = Math.floor(Math.random() * 999999);
$("#class_posts").load("../trida/get_posts.php?"+randNum);