【发布时间】:2012-06-10 00:41:03
【问题描述】:
这是我的问题 - 我有包含“file.php”和数据库内容的 Div 然后我将新数据插入数据库并希望将 .load() file.php 重新加载到 div 但内容相同,直到我刷新页。有人知道它是什么吗? 文件.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>
";
}
}
?>
有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("");
});
}
【问题讨论】:
-
你从哪里得到
data?有成功参数吗? -
是的,它的 $.Ajax JSON 表单并且可以正常工作
-
我问的唯一原因是因为您提到了不支持 JSON 的
.load,并且根据您上面发布的内容,您的 php 似乎没有返回 json。 -
啊,我明白了。
?_=" + $.now()应该可以工作,但它与 ahren 答案中的 rand num 解决方案相同。 -
您的数据库查询非常对 SQL 注入开放。请阅读 SQL 注入,如何防止它,并考虑使用 PDO 转移到准备好的语句。 不要发布此代码。请。