我已經創建了一個頁面「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