我有以下index.php文件:
<html lang="en">
<head>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
var auto_refresh = setInterval(function (){
//alert("abc");
$('#mydiv').load('xyz.php').fadeIn("slow");
}, 1000);
});
</script>
</head>
<body>
<div id="mydiv"> </div>
</body>
</html>
在上面的文件中,我试图在1秒后调用我的xyz.php文件。它的工作正常。
以下是我的xyz.php文件。
<?php
//echo rand();
$questions=array(
"Array Item 1",
"Array Item 2",
"Array Item 3");
?>
早些时候,我调用rand函数,该函数每隔一秒钟调用一次该文件便会生成随机数。现在,我已将其注释掉。我的要求已更改。现在,我希望在首次调用此文件时,回显数组项1。第二次回显数组项2。第三次尝试类似的阵列项目3。此setInterval之后不应调用此php文件。
在这里我需要你的帮助。
参考方案
在JS中:
var count = 0;
$(document).ready(function(){
var auto_refresh = setInterval(function (){
$('#mydiv').load('xyz.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);
});
在PHP中:
<?php
$questions=array(
"Array Item 1",
"Array Item 2",
"Array Item 3");
if (isset($_POST["count"])) {
echo $questions[intval($_POST["count"])];
}
?>
PHP-复选框组 - php我有一个需要发布的表单复选框组。<input type="checkbox" value="true" checked name="chk0[]"> <input type="checkbox" value="false" name=…
php Singleton类实例将在多个会话中保留吗? - php举一个简单的例子,如果我想计算一个不使用磁盘存储的脚本的命中次数,我可以使用静态类成员来执行此操作吗?用户1:<?php $test = Example::singleton(); $test->visits++; ?> 用户2:<?php $test = Example::singleton(); $test->visits+…
Div单击与单选按钮相同吗? - php有没有一种方法可以使div上的click事件与表单环境中的单选按钮相同?我只希望下面的div提交值,单选按钮很丑代码输出如下:<input id="radio-2011-06-08" value="2011-06-08" type="radio" name="radio_date…
未提交附加字段值 - php我在PHP中有一组表单字段。我还添加了jQuery功能来克隆某些字段并将其添加到表单中。但是,在提交表单后,仅提交原始字段,而不提交通过克隆添加的字段。的PHP<form id="myForm" method="post" action"..."> <div class="…
jQuery克隆div内容的次数不定 - phpjQuery:$('#partsOrderQty').blur(function(){ var rowCounter = $(this).val(); console.log(rowCounter); var toAddRow = $("#skidListings").children().clone(); for (…