我工作的刷新與PHP和JQuery一個DIV。我測試上,我將使用(以.php)的實際文件和我做了一個test.html的文件。由於某些原因,test.html文件可以正常工作,但.php文件不能。PHP的jQuery刷新DIV
的test.html:
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script type="text/javascript">// <![CDATA[
$(document).ready(function() {
$.ajaxSetup({ cache: false }); // This part addresses an IE bug. without it, IE will only load the first number and will never refresh
setInterval(function() {
$('#results').load('content.php');
}, 3000); // the "3000" here refers to the time to refresh the div. it is in milliseconds.
});
// ]]></script>
</head>
<body>
<div id="results">Loading users...</div>
</body>
</html>
view_conversation.page.inc.php(消息傳遞系統的一部分):
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script type="text/javascript">// <![CDATA[
$(document).ready(function() {
$.ajaxSetup({ cache: false }); // This part addresses an IE bug. without it, IE will only load the first number and will never refresh
setInterval(function() {
$('#list').load('content.php');
}, 3000); // the "3000" here refers to the time to refresh the div. it is in milliseconds.
});
// ]]></script>
</head>
<?php
$errors = array();
$valid_conversation = (isset($_GET['conversation_id']) && validate_conversation_id($_GET['conversation_id']));
if ($valid_conversation === false){
$errors[] = 'Invalid Conversation ID.';
}
if (isset($_POST['message'])){
if (empty($_POST['message'])){
$errors[] = 'You must enter a message.';
}
if (empty($errors)){
add_conversation_message($_GET['conversation_id'], $_POST['message']);
}
}
if (empty($errors) === false){
foreach ($errors as $error){
echo $error;
}
}
if ($valid_conversation){
/*if (isset($_POST['message'])){
update_conversation_last_view($_GET['conversation_id']);*/
$messages = fetch_conversation_messages($_GET['conversation_id']);
}else{
$messages = array();
update_conversation_last_view($_GET['conversation_id']);
}
session_start();
$_SESSION['messages']=$messages;
?>
<a href="index.php?page=inbox">Inbox</a>
<a href="index.php?page=logout">Logout</a>
<form action="" method="post">
<p><textarea name="message" rows="10" cols="85"></textarea></p>
<p><input type="submit" value="Add Message" /></p>
</form>
<?php
//var_dump($messages);
if($messages){
?><html><body>
<div id='list'>Loading messages...</div>
</body></html><?php
}
?>
</html>
我的問題是:爲什麼test.html的工作時view_conversation .inc.php沒有(順便說一下,content.php文件只包含一個用於測試目的的回聲)
請幫助我。
預先感謝您。
你歌廳任何錯誤,同時刷新後加載PHP文件? –
不,這個.php根本不會刷新,它只是顯示原始的加載消息... – user3315726
我也嘗試添加div到PHP的開頭,但得到了相同的結果 – user3315726