gpt4 book ai didi

javascript - 显示一条消息直到 php 脚本完成

转载 作者:行者123 更新时间:2023-11-29 22:18:44 26 4
gpt4 key购买 nike

这是我上传excel文件并将其中的数据导入mysql表的页面。由于查询需要一些时间才能完成,我想显示一个 GIF 文件,显示“正在加载”,直到插入整个记录,然后将图像更改为完成。请解决任何问题。

<?php

require_once('Connections/met.php');
$uploadedStatus = 0;

if ( isset($_POST["submit"]) ) {
if ( isset($_FILES["file"])) {
//if there was an error uploading the file
if ($_FILES["file"]["error"] > 0) {
echo "Return Code: " . $_FILES["file"]["error"] . "<br />";
}
else {
if (file_exists($_FILES["file"]["name"])) {
unlink($_FILES["file"]["name"]);
}
$storagename = "windrose_data.xlsx";
move_uploaded_file($_FILES["file"]["tmp_name"], $storagename);
$uploadedStatus = 1;
}
} else {
echo "No file selected <br />";
}
}

if($uploadedStatus==1){

$db=mysql_select_db($database_met,$met);

set_include_path(get_include_path() . PATH_SEPARATOR . 'Classes/');
include 'PHPExcel/IOFactory.php';

// This is the file path to be uploaded.
$inputFileName = 'windrose_data.xlsx';

try {
$objPHPExcel = PHPExcel_IOFactory::load($inputFileName);
} catch(Exception $e) {
die('Error loading file "'.pathinfo($inputFileName,PATHINFO_BASENAME).'": '.$e->getMessage());
}


$allDataInSheet = $objPHPExcel->getActiveSheet()->toArray(null,true,true,true);
$arrayCount = count($allDataInSheet); // Here get total count of row in that Excel sheet

for($i=2;$i<=$arrayCount;$i++){
$date = trim($allDataInSheet[$i]["A"]);
$time = trim($allDataInSheet[$i]["B"]);
$dir = trim($allDataInSheet[$i]["C"]);
$spd = trim($allDataInSheet[$i]["D"]);

$insertTable= mysql_query("insert into wr_copy (date,time,dir,spd) values('$date', '$time',$dir,$spd)") or die(mysql_error());

$msg = 'Record has been added. <div style="Padding:20px 0 0 0;"><a href="">Go Back to tutorial</a></div>';

}
echo "<div style='font: bold 18px arial,verdana;padding: 45px 0 0 500px;'>".$msg."</div>";

}

?>

<html>

<head>
<title>Import Excel file </title>
<script type="text/javascript" src="js/jquery-1.5.1.js"></script>
<script type="text/javascript" src="js/jquery-ui/js/jquery-ui-1.10.2.custom.js"></script>
<script type="text/javascript" src="js/jquery-ui/js/jquery-ui-1.10.2.custom.min.j"></script>

<script type="text/javascript">

jQuery.noConflict();

</script>

</head>

<body>

<table width="600" style="margin:115px auto; background:#f8f8f8; border:1px solid #eee; padding:10px;">

<form action="<?php echo $_SERVER["PHP_SELF"]; ?>" method="post" enctype="multipart/form-data">

<tr>
<td width="50%" style="font:bold 12px tahoma, arial, sans-serif; text-align:right; border-bottom:1px solid #eee; padding:5px 10px 5px 0px; border-right:1px solid #eee;">Select file</td>
<td width="50%" style="border-bottom:1px solid #eee; padding:5px;"><input type="file" name="file" id="file" /></td>
</tr>
<tr>
<td style="font:bold 12px tahoma, arial, sans-serif; text-align:right; padding:5px 10px 5px 0px; border-right:1px solid #eee;">Submit</td>
<td width="50%" style=" padding:5px;"><input type="submit" name="submit" /></td>
</tr>

</table>

</form>

</body>
</html>

最佳答案

您已经使用了 jQuery,但看起来没有使用 jQuery ajax/post 方法来提交表单,这将是理想的方法。目前的一种快速方法是将 onsubmit 事件 hadaller 添加到表单并在表单提交事件上显示加载图像/消息。

<form action="<?php  echo $_SERVER["PHP_SELF"]; ?>" method="post" enctype="multipart/form-data" onsubmit="$('#loading').show(); return true;">
<div id='loading' style='display:none'> Loading message / Image Here...</div>

关于javascript - 显示一条消息直到 php 脚本完成,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30950795/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com