【发布时间】:2020-08-13 22:02:57
【问题描述】:
我有一个与某些软件交互的用户界面。
我的用户界面显示一个带有数据路径的数据库。用户选择他们想要模拟/运行的数据路径,然后将数据路径发送到软件。完成后,输出是保存在同一台计算机上的文件夹中的 excel 报告。这是我对如何准确地向用户显示用户选择模拟/运行的指定数据路径的 excel 报告感到有点困惑。
我的想法是创建一个例程,将 excel 报告转换为 pdf,然后将报告的文件路径保存到数据库。然后,我创建一个 id="result" 的 div,以显示在所选指定路径的表格行内,并加载 pdf_report.php,然后显示所需的报告。
问题是每次我重新加载页面时 div 标签都会消失。我尝试使用 localstorage,但页面重新加载后仍然没有显示。
我的代码如下:
**让用户模拟/运行所选路径
Search.php
<?php
...
while($row = $result->fetch_assoc()){
$field1name = $row["test_id"];
$field2name = $row["path"];
$field3name = $row["video1_path"];
$field4name = $row["video2_path"];
$field5name = $row["video3_path"];
$field6name = $row["video4_path"];
echo "<tr>
<td> ".$field1name." </td>
<td> ".$field2name." </td>
<td> ".$field3name." </td>
<td> ".$field4name." </td>
<td> ".$field5name." </td>
<td> ".$field6name." </td>
<td><div>
<button class='edit' id='" . $row['test_id'] . "' >Run</button>
</div></td>
<td><div id='result'>
<p></p>
</div></td>
</tr>";
}
}else {
echo '<span style="color:#ff0000;text-align:center;">No Test ID Selected!</span>';
}
}
// Close connection
mysqli_close($conn);
?>
</table>
</div><br>
<div style="overflow-x:auto;">
<table id=test_data>
<tr>
<th>Progress</th>
<th>Progress Status</th>
</tr>
<tr>
<td><div><progress id='progBar' value='0' max='100'></progress></div></td>
<td><div><p id='progress-text'></p></div></td>
</tr>
</table>
</div>
<script type="text/javascript">
var show = localStorage.getItem('showDiv');
if(show === 'true'){
$("#result").show();
}
</script>
<!--Uses jquery to run 3 scripts and displays it in a progress bar-->
<script>
$(document).on('click', '.edit', function(event){
//set cookie value to 'path'
var fcookie='mycookie';
//if button inside row is clicked the path gets saved to a cookie and received in ajax.php
var test_id = $(this).attr('id');
if(test_id) {
var path = $(this).closest('tr').find("td:nth-child(2)").text();
//Cookie gets saved
document.cookie='fcookie='+path;
var $this = $(this);
//Start of 1st script
$.ajax({
url: "ajax.php",
type:"POST",
success: function(data) {
//alert("File 1 Completed")
$("#progress-text").text("Executing file 1");
$('#progBar').val(25);
//Start of 2nd script
$.ajax({
url: "ajax2.php",
type:"POST",
success: function(data2) {
//alert("File 2 Completed")
$("#progress-text").text("Executing file 2");
$('#progBar').val(50);
//Start of 3rd script
$.ajax({
url: "ajax3.php",
type:"POST",
success: function(data3) {
//alert("File 2 Completed")
$("#progress-text").text("Complete");
$('#progBar').val(100);
//Displays the <div id=result> for the selected data path
$this.closest("tr").find("td:nth-child(8)").load("pdf_report.php");
event.preventDefault();
$("#result").show();
localStorage.setItem('showDiv', true);
}
});
}
});
}
});
}
});
</script>
【问题讨论】:
-
此报告是为特定用户生成的吗?如果是这样,您将需要一些机制来识别用户。通常,sessions 用于此目的。
-
不,所有用户都会得到相同的报告。它是一个 localhost 项目,用户将通过本地网络的 IP 访问该网站
-
好奇:这是如何通过 localhost 工作的?本地主机,顾名思义,就是自己的电脑。 (所以每个运行它的人都有不同的本地主机——他们自己的电脑)你在所有用户的计算机上都加载了 XAMPP 吗?还是您公司中的一台计算机被指定为“网络服务器”并且每个人都连接到它?或者,是否只有一台每个人都亲自访问以运行程序的计算机接收他们的报告?
Waterloomatt关于识别用户的常用方法是正确的。您必须非常清楚地解释每个人如何连接到您的应用,因为我不确定我是否理解。 -
是的,将有一台计算机用于加载代码,指定为“网络服务器”,运行/使用用户界面的任何人都将仅连接到该计算机。跨度>
标签: php jquery local-storage