【发布时间】:2022-12-22 01:04:13
【问题描述】:
在我们的页面中,有 1 个输入必须由用户手动输入。根据他输入的内容,显示了一些记录,每个结果旁边都有禁用或启用(例如,我输入12345,结果是A,B,C,D,4个结果和除了这些结果之外,还有禁用按钮侧。)。目前,发生的情况是当我单击“禁用”或“启用”时,页面会自动重新加载,但我找不到修复它的方法。无论如何要停止重新加载?我使用window.history.go(-1)。它会更新数据库,但每次我禁用或启用时页面都会重新加载。
下面是HTML代码。
<body onload="OnLoad()">
<form class="form-horizontal" name="translot" method="post">
<form id="form" method="post">
<div class="col" style="width: 580px; font-weight: bold; border: 1px solid SteelBlue; color: #6699CC; margin-left: 170px;">
<p style="background-color: #6699CC; font-size: 16px; width: 580px; padding: 5px; color: #FFF; font-weight: bold; margin-left: -1px;margin-top: -1px;"></p>
<div class="form-group">
<br>
<label class="control-label col-sm-4" for="productlotid">Lot ID:</label>
<div class="col-sm-4">
<p class="form-control-static" style="margin-top: -6px;">
<input type="text" class="form-control" id="productlotid" name="productlotid" onkeydown="return KeyDown()" onkeyup="this.value=this.value.toUpperCase()" onkeypress="return searchKeyPress(event)" min="1" placeholder="Enter Lot ID" value="<?php echo $productlotid; ?>">
</p>
<?php
include("correlationwafer_result.php");
?>
</div>
<div id="result" style="display: inline-table; margin-left: 150px; margin-top: 22px;"></div>
<!--div id="result" ></div-->
<div class="col-sm-10">
</div>
<br>
</div>
</div>
<br>
<div style="margin-right: 65px;">
<p align="center"><button type="button" class="btn btn-info " name="cmdSubmit" id="cmdSubmit" onclick="Submit()"><b>Go</b></button> <button type="button" class="btn btn-warning" name="cmdReset" onclick="Reset()"><b>Reset</b></button></p>
</div>
</form>
</form>
以下是来自 correlationwafer_result.php 的 php 代码。
<?php
// ini_set("memory_limit","512M");
include("_dbconn.php");
include("//sgewsnant21.amk.st.com/ewsweb/wwwroot/library/common7/db_config.inc");
include("//sgewsnant21.amk.st.com/ewsweb/wwwroot/library/common7/standard_defines.inc");
session_start();
$productlotid = isset ($_GET['productlotid'])? $_GET['productlotid']:'';
//$sql1 = "Update * FROM productdb.tbl_correlationwafer WHERE lotid = '$productlotid' ORDER BY lotid and zone_enable='0'";
$sql = "SELECT * FROM productdb.tbl_correlationwafer WHERE lotid = '$productlotid' ORDER BY product asc, zone asc";
$result1 = mysqli_query($conn,$sql);
echo "<table id='corwafer'>";
$arr = array();
while ($row = mysqli_fetch_assoc($result1)) {
$field1name = $row["lotid"];
$field2name = $row["product"];
$field3name = $row["ewsflow"];
$field4name = $row["zone"];
$field5name = $row["zone_enable"];
$key = $field1name + ":" + $field2name + ":" + $field3name;
if (!in_array($key, $arr)){
array_push($arr, $key);
}
?>
<form action='test.php' method='post' enctype='multipart/form-data'>
<?php
echo "<tr>";
echo "<td>";
if($field5name == 1){
echo "<input type='hidden' id='chkzone' name='chkzone' value='$field4name'>";
echo "<input type='hidden' id='pid' name='pid' value='$field1name'>";
echo" <label for='chkzone'> Product - $field2name </label>";
echo" <label for='chkzone'> :: Zone - $field4name </label>";
//echo" <label for='chkzone'> :: Zone - $field4name </label>";
echo "<a class='btn btn-secondary text-light btn-sm' href='test.php?id=$field4name&pid=$field1name'>Disable</a>";
}
else if($field5name == 0){
echo "<input type='hidden' id='chkzone' name='chkzone' value='$field4name'>";
echo "<input type='hidden' id='pid' name='pid' value='$field1name'>";
echo" <label for='chkzone'> Product - $field2name </label>";
echo" <label for='chkzone'> :: Zone - $field4name </label>";
//echo" <label for='chkzone'> :: Zone - $field4name </label>";
echo "<a class='btn btn-secondary text-light btn-sm' href='test_1.php?id=$field4name&pid=$field1name'>Enable</a>";
}
echo "</td>";
echo "</tr>";
?>
</form>
<?php
}
echo "</table>";
flush();
mysqli_close($conn);
?>
以下代码来自test.php页面。
<?php
// ini_set("memory_limit","512M");
include("_dbconn.php");
include("//sgewsnant21.amk.st.com/ewsweb/wwwroot/library/common7/db_config.inc");
include("//sgewsnant21.amk.st.com/ewsweb/wwwroot/library/common7/standard_defines.inc");
session_start();
$zone = $_GET['id'];
$pid = $_GET['pid'];
$updateQuery = "UPDATE productdb.tbl_correlationwafer SET zone_enable='0' WHERE zone='$zone' AND lotid='$pid'";
$result = mysqli_query($conn,$updateQuery);
if($result){
echo "<script>window.history.go(-1);</script>";
//echo "<script>return false;</script>";
}else{
echo "<script>window.history.go(-1);</script>";
//echo "<script>return false;</script>";
}
flush();
mysqli_close($conn);
?>
以下来自test_1.php。
<?php
// ini_set("memory_limit","512M");
include("_dbconn.php");
include("//sgewsnant21.amk.st.com/ewsweb/wwwroot/library/common7/db_config.inc");
include("//sgewsnant21.amk.st.com/ewsweb/wwwroot/library/common7/standard_defines.inc");
session_start();
$zone = $_GET['id'];
$pid = $_GET['pid'];
$updateQuery2 = "UPDATE productdb.tbl_correlationwafer SET zone_enable='1' WHERE zone='$zone' AND lotid='$pid'";
$result = mysqli_query($conn,$updateQuery2);
if($result){
echo "<script>window.history.go(-1);</script>";
//echo "<script>return false;</script>";
}else{
echo "<script>window.history.go(-1);</script>";
//echo "<script>return false;</script>";
}
flush();
mysqli_close($conn);
?>
【问题讨论】:
-
您不必单击链接,而是必须使用 AJAX,将必要的参数发送到服务器,并在 JavaScript 中处理响应。
-
身份证属性必须是唯一的,因此在循环中生成多个元素将打破该规则
-
@CBroe 我以前从未使用过 ajax。你能给我举个例子吗?
标签: javascript php database reload