以下是我的index.php文件
<html>
<head>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script type="text/javascript">
var count = 0;
$(document).ready(function(){
var auto_refresh = setInterval(function (){
$('#mydiv').load('a.php', {count: count}, function () {
count = count + 1;
//after three attempts it won't call php file.
if (count > 2) {
clearInterval(auto_refresh);
}
}).fadeIn("slow");
}, 1000);
});
</script>
</head>
<body>
<div id="mydiv"> </div>
</body>
</html>下面是我的a.php文件
<?php
$questions=array(
"Array Item 0",
"Array Item 1",
"Array Item 2");
if (isset($_GET["count"]))
{
echo $questions[intval($_GET["count"])];
}
else
{
echo rand();
}
?>上面代码的问题是php文件中的其他部分总是在运行。这意味着我一个接一个地得到3个随机数,但是我想一个一个地得到数组的所有三个记录。我认为isset($_GET["count"])不起作用。但为什么我不知道。请帮个忙。
发布于 2013-10-18 09:17:25
这个a.php适用于我:
<?php
$questions=array(
"Array Item 0",
"Array Item 1",
"Array Item 2");
if (isset($_POST["count"]))
{
echo $questions[intval($_POST["count"])];
}
else
{
echo rand();
}
?>你的数据是"POSTed“吗?
加:
我在jQuery页面上找到了这个:
请求方法
如果将数据作为对象提供,则使用POST方法;否则,假设为GET。
https://stackoverflow.com/questions/19445265
复制相似问题