我想在执行页面5秒后执行页面脚本
表示如果我访问http://localhost/form.php
,则等待5秒钟,然后处理该页面的全部内容。
我的页面是
<?php
$con=mysqli_connect("localhost","root","","ex_smartcard2013");
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$result3 = mysqli_query($con,"SELECT id,name,course,amount FROM fess order by id desc limit 1");
while($row = mysqli_fetch_array($result3))
{
if($row['name'])
{
$id = $row['id'];
$name = $row['name'];
$course = $row['course'];
$amount = $row['amount'];
}
}
?>
<div style="display:none;">
<iframe id="ponyo_frame" name="ponyo_frame"></iframe>
<div class="ss-form"><form action="https://docs.google.com/forms/d/1IDfOSwEcNYwvqxBHlGOTmPbZQrS7vr7Q1xw77UBVLUc/formResponse" method="POST" id="ss-form" target="ponyo_frame" onsubmit=""><ol style="padding-left: 0">
<input type="text" name="entry.1312370642" value="<?php echo $id; ?>" class="ss-q-short" id="entry_1312370642" dir="auto" title="">
<input type="text" name="entry.1082361902" value="<?php echo $name; ?>" class="ss-q-short" id="entry_1082361902" dir="auto" title="">
<input type="text" name="entry.234382219" value="<?php echo $course; ?>" class="ss-q-short" id="entry_234382219" dir="auto" title="">
<input type="text" name="entry.1270326869" value="<?php echo $amount; ?>" class="ss-q-short" id="entry_1270326869" dir="auto" title="">
</div></div><script type="text/javascript">
document.getElementById("ss-form").submit();
</script>
</div>
答案 0 :(得分:1)
PHP是服务器端,它处理请求,发送响应并停止,每个新请求都是新的程序实例,当您查看页面时,没有PHP正在运行,它只在您“请求”时运行“内容。
你必须使用JavaScript来做客户端:
<script type="text/javascript">
setTimeout(function() {
//some ajax call that will call another php script and trigger your MySQL query
...
}, 10000);
</script>
如果您需要获得有关如何运行Ajax查询的说明,请查看JQuery http://api.jquery.com/jQuery.ajax/(文档)http://learn.jquery.com/ajax/(教程)
答案 1 :(得分:0)
例如:
<body>
<div class="empty"></div>
</body>
<script>
$(document).ready(function(){
// The code throw javascript to render the page html
$('.empty').append('
<form>
<input type="text" value="Type Here" />
</form>
');
}).delay(5000);
</script>
这不是一个好习惯,但它会帮助你做你想做的事 您还需要添加jquery