【发布时间】:2014-02-17 10:00:08
【问题描述】:
我正在使用 PHP 和 JQuery 刷新 DIV。我正在测试我将使用的实际文件(.php)和我制作的 test.html 文件。出于某种原因,test.html 文件有效,而 .php 文件无效。
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 根本不刷新,它只是显示原始加载消息...
-
我也尝试将 div 添加到 php 的开头,但得到了相同的结果
-
为什么在 .php 文件的 html 标签中包含 php?
-
好地方。我已经改变了它,但不幸的是它没有改变结果