gpt4 book ai didi

php - Ajax 脚本未加载任何内容且未发送任何请求

转载 作者:行者123 更新时间:2023-11-28 10:21:02 25 4
gpt4 key购买 nike

这个脚本应该每秒运行一个 jQuery Ajax 脚本,它应该获取所有较新的帖子,然后将它们放在原始帖子之上。但目前什么也没有发生,它加载了最初的帖子,但没有其他任何事情。 Firebug 控制台没有报告任何错误,或者根本没有发送任何 Ajax 请求。您能看出这个脚本有什么问题可能导致这种情况吗?谢谢:)

源代码-index.php(我省略了CSS):

<?php
include('config.php');
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Twitter Style load more results.</title>
<link href="frame.css" rel="stylesheet" type="text/css">
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/
libs/jquery/1.3.0/jquery.min.js"></script>

<script type="text/javascript">
$(function () {
$(function () {
setInterval(oneSecondFunction, 1000);
});

function oneSecondFunction() {
var ID = $(this).attr("id");
if (ID) {
$("#more" + ID).html('<img src="moreajax.gif" />');

$.ajax({
type: "POST",
url: "ajax_more.php",
data: "lastmsg=" + ID,
cache: false,
success: function (html) {
$("ol#updates").prepend(html);
$("#more" + ID).remove();
}
});
} else {

}


return false;


};
});
</script>
</head>
<body>
<div id='container'>
<ol class="timeline" id="updates">
<?php
$sql=mysql_query("select * from updates ORDER BY item_id DESC LIMIT 9");
while($row=mysql_fetch_array($sql))
{
$msg_id=$row['item_id'];
$message=$row['item_content'];
?>
<li>
<?php echo $message; ?>
</li>
<?php } ?>
</ol>
</div>
</body>
</html>

ajax_more.php-

 <?php
include("config.php");


if(isset($_POST['lastmsg']))
{
$lastmsg=$_POST['lastmsg'];
$result=mysql_query("select * from updates where item_id<'$lastmsg' order by item_id desc limit 9");
$count=mysql_num_rows($result);
while($row=mysql_fetch_array($result))
{
$msg_id=$row['item_id'];
$message=$row['item_content'];
?>


<li>
<?php echo $message; ?>
</li>


<?php
}


?>
<?php
}
?>

最佳答案

开头的一些代码看起来是错误的。这应该有效。每秒都会调用 oneSecondFunction:

$(document).ready(function() {

setInterval(oneSecondFunction, 1000);


function oneSecondFunction() {
//console.log('run oneSecondFunction');
var ID = $(this).attr("id");
if(ID) {
$("#more"+ID).html('<img src="moreajax.gif" />');
$.ajax({ type: "POST", url: "ajax_more.php", data: "lastmsg="+ ID, cache: false,
success: function(html){
$("ol#updates").prepend(html);
$("#more"+ID).remove();
}
});
} else {
} return false; };
});

关于php - Ajax 脚本未加载任何内容且未发送任何请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5668275/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com