-1

我想在执行页面 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>
4

2 回答 2

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/(教程)

于 2013-09-29T16:20:47.117 回答
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

于 2013-09-29T16:24:12.263 回答