显示加载图像,直到动态内容可用并加载新页面

时间:2015-08-21 15:38:34

标签: javascript php mysql

这是我需要做的。

我有一个php页面,它会生成一个像site.com/result.php?id=355这样的页面,还有从MySql数据库中获取的动态内容。

问题:在内容甚至存在于Mysql数据库中之前,用户被重定向到该页面(它仍然在服务器端处理)。这意味着用户必须刷新页面几次,持续约3秒,结果就在那里。

我希望显示加载图像,而内容在数据库中之前没有任何内容可显示。一旦内容可以显示,它应该自动打印,而无需用户手动刷新页面。

代码: 文件上传和重定向:                ">

<input type="hidden" name="MAX_FILE_SIZE" value="10485760" />
                      <input name="userfile" type="file"  id="exampleInputFile">
                      <p class="help-block">Select File To Crypt.</p>
                     <!--  <input type="hidden" name="MAX_FILE_SIZE_BIND" value="10485760" />
                      <input name="binded" type="file"  id="exampleInputFile">
                      <p class="help-block">Select File To Bind</p> -->
                      <p>
                          <button type="submit" name="submit"  class="btn full-width btn-primary">Crypt and Scan</button>
                      </p> 
                      </form>
<?php  
if (!isset($_POST['submit'])) 
{ 
} else 
{   
mysql_connect("localhost", "scarr", "12345") or
    die("Could not connect: " . mysql_error());
mysql_select_db("scar");

    $uploaddir = '/var/www/html/upl/';
$_rand = generateRandomString();
$_namerand = $_rand . ".exe" ;
$uploadfile = $uploaddir .$_namerand ;


if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) {
if ($_FILES['MAX_FILE_SIZE']['size'] == 0 && $_FILES['MAX_FILE_SIZE']['error'] == 0)
{

}
$linked = "http://192.168.129.137/upl/" . $_namerand;
$sql = mysql_query("INSERT INTO Task (link, name) VALUES ('$linked', '$_rand')");
if (!$sql) {
    echo 'Could not run query: ' . mysql_error();
    exit;
}

 ?>
<form name='redirect' action='result.php?name=' method='GET'>
<input type='hidden' name='name' value='<?php echo $_rand; ?>'>


<script type='text/javascript'>
document.redirect.submit();
</script>
</form> 
<?php

} else {

}




} 

function generateRandomString($length = 8) {
    $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
    $randomString = '';
    for ($i = 0; $i < $length; $i++) {
        $randomString .= $characters[rand(0, strlen($characters) - 1)];
    }
    return $randomString;
}
?>

代码结果页面:

<?php
mysql_connect("localhost", "scar", "12345") or
    die("Could not connect: " . mysql_error());
mysql_select_db("scanner");
$namestr = $_GET["name"];
$result = mysql_query("SELECT id,name,Result FROM Results WHERE name = '$namestr'");
if (!$result) {
    echo 'Could not run query: ' . mysql_error();
    exit;
}
$row = mysql_fetch_row($result);




?>

<div id="content">
<h1><center><font color="green">{ 0/42 }</font></center></h1>
          <table><thead><th>LiveGr Name</th><th>Result</th></thead>
          <tr><td>LiveGridSys </td><td><font color ='Red'><?php printf($row[2])?></font></td></tr>
          </table>

0 个答案:

没有答案