我已经创建了一个页面“index.php”与很多divs,我只需要刷新表单提交时只有一个divs。从提交表格加载php的动态内容
这个div加载从chat_window.php这是如下内容:
<div id="chatbox">
<?php echo $res; ?>
</div>
<!-- Chat user input form-->
<?php echo $formchat; ?>
chat_window.php使用动态内容 - $res
和$formchat
从chat.php。 每次我发布表单时,$ res和$ formchat的内容都会被修改,我需要在加载chat_window.php的页面中反映相同的内容。
我使用AJAX和jQuery做同样如下:
$(document).ready(function() {
$("#submit").click(function() {
var name = $("input#chat").val();
var dataString = "chat="+ name;
$.ajax({
type: "POST",
url: "programo/bot/chat.php",
data: dataString,
success: function() {
}
});
$("#chatwrapper").load(chat_window.php);
return false;
});
});
的index.php文件有一个div来显示chat_window如下:
<!-- Chat window-->
<div id="chatwrapper">
<?php include ("chat_window.php"); ?>
</div>
按我的分析,当我发布表单,$ res和$ formchat在php中得到更新。但是当我加载chat_window.php时,它不会加载修改后的值。它相当于加载了初始静态值。 (请不要建议setInterval()
,因为我不想自动刷新页面)。
感谢您的回复。我甚至尝试了以上。不幸的是,它不工作。 :( – 2012-01-10 05:56:17
是否有任何Javascript错误出现?尝试使用Firebug来查看来自ajax调用的响应 – SeanNieuwoudt 2012-01-10 11:28:40