我有一个表格,我在其中选择项目名称并输入工作表名称。单击提交按钮后,它以表格格式显示最后插入的记录,但单击提交后,它会显示表格,但一旦重新加载页面,它就会隐藏表格。并单击提交按钮,它会显示表格。我该如何解决这个问题?
<button type="submit" name="submit" id="button" class="btn-success btn">Submit</button>
<script>
$(document).ready(function() {
$("#button").click(function() {
$("#table").show();
});
});
</script>
<?php
include('controller.php');
$s4 = "SELECT * FROM col_heading ORDER BY coln_id DESC LIMIT 1";
$res = mysqli_query($bd, $s4);
while ($row = mysqli_fetch_array($res)) {
?>
<table class="table table-bordered" id="table" style="width:50%;">
<thead>
<tr>
<th>Sr.no</th>
<th>Column Name</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td>1</td>
<td id="h1:<?php echo $row['coln_id']; ?>" contenteditable="true">
<?php echo $row['h1']; ?>
</td>
</tr>
<tr>
<td>2</td>
<td id="h2:<?php echo $row['coln_id']; ?>" contenteditable="true">
<?php echo $row['h2']; ?>
</td>
</tr>
<tr class="odd">
<td>3</td>
<td id="h3:<?php echo $row['coln_id']; ?>" contenteditable="true">
<?php echo $row['h3']; ?>
</td>
</tr>
</tbody>
</table>
<?php
}
?>
尝试e.preventDefault();
在您的提交中使用。
$(document).ready(function() {
$("#button").click(function(e) {
e.preventDefault();
$("#table").show();
});
});
如果你想在提交时做一些事情,那么最好在 click 函数中使用 ajax 调用并完成它。
将你的 php 放在一个新文件中
更新.php
<?php
include('controller.php');
$s4 = "SELECT * FROM col_heading ORDER BY coln_id DESC LIMIT 1";
$res = mysqli_query($bd, $s4);
while ($row = mysqli_fetch_array($res)) {
?>
从内部单击函数对 update.php 进行 ajax 调用
$(document).ready(function() {
$("#button").click(function(e) {
e.preventDefault();
$("#table").show();
$.ajax({
url: 'update.php',
data: '<pass any data here>',
success: function(response){
// do something with the resposne
}
});
});
});
完整代码
<button type="submit" name="submit" id="button" class="btn-success btn">Submit</button>
<script>
$(document).ready(function() {
$("#button").click(function(e) {
e.preventDefault();
$("#table").show();
$.ajax({
url: 'update.php',
data: '<pass any data here>',
success: function(response){
// do something with the resposne
}
});
});
});
</script>
<table class="table table-bordered" id="table" style="width:50%;">
<thead>
<tr>
<th>Sr.no</th>
<th>Column Name</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td>1</td>
<td id="h1:<?php echo $row['coln_id']; ?>" contenteditable="true">
<?php echo $row['h1']; ?>
</td>
</tr>
<tr>
<td>2</td>
<td id="h2:<?php echo $row['coln_id']; ?>" contenteditable="true">
<?php echo $row['h2']; ?>
</td>
</tr>
<tr class="odd">
<td>3</td>
<td id="h3:<?php echo $row['coln_id']; ?>" contenteditable="true">
<?php echo $row['h3']; ?>
</td>
</tr>
</tbody>
</table>
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句