首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何使用jquery和PHP定期显示数组项?

问如何使用jquery和PHP定期显示数组项?
EN

Stack Overflow用户
提问于 2013-10-18 08:44:35
回答 1查看 256关注 0票数 0

以下是我的index.php文件

代码语言:javascript
复制
<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文件

代码语言:javascript
复制
<?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"])不起作用。但为什么我不知道。请帮个忙。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-10-18 09:17:25

这个a.php适用于我:

代码语言:javascript
复制
<?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。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/19445265

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档