我为网页创建了搜索功能,以便它可以更新信息.当我搜索记录并更新信息时.然后返回以再次搜索记录,显示原始信息.我检查了MySQL数据库,它确实表明信息已更改,不确定为什么会发生这种情况.有人遇到过这个问题吗?
这是我的index.php表格
Inventory Integrity Edit Request
Form
Enter
Request ID #
placeholder="Type the id" type="text">
"input-group-btn">
"btn btn-default btnSearch" type="button">
"input-group-btn">
"input-group-btn">
"input-group-btn">
"input-group-btn">
"input-group-btn">
"glyphicon glyphicon-search">Search
"resultTable">
IdNamelanIdDepartmentManagerWork RequestedPOISRequest Comments
jQuery(document).ready(function($) {
$('.btnSearch').click(function(){
makeAjaxRequest();
});
$('form').submit(function(e){
e.preventDefault();
makeAjaxRequest();
return false;
});
function makeAjaxRequest() {
$.ajax({
url: 'php/search.php',
type: 'get',
data: {id: $('input#id').val()},
success: function(response) {
$('table#resultTable tbody').html(response);
}
});
}
});
这是我的search.php表格
require_once 'db_connect.php';
$conn = dbConnect();
$OK = true; // We use this to verify the status of the update.
if (isset($_GET['id'])) {
// Create the query
$data = "%".$_GET['id']."%";
$sql = 'SELECT * FROM requests WHERE id like ?';
$stmt = $conn->prepare($sql);
$results = $stmt->execute(array($data));
$rows = $stmt->fetchAll();
$error = $stmt->errorInfo();
//echo $error[2];
}
// If there are no records.
if(empty($rows)) {
echo "
";echo "
There were not records";echo "
";}
else {
foreach ($rows as $row) {
echo "
";$id = $row['id'];
echo "
$id";echo "
".$row['name']."";echo "
".$row['lanId']."";echo "
".$row['department']."";echo "
".$row['mgrname']."";echo "
".$row['work_requested']."";echo "
".$row['purchase_order']."";echo "
".$row['inbound_shipment']."";echo "
".$row['request_comments']."";echo "
";}
}
?>
解决方法:
禁用ajax缓存:
$.ajax({
url: 'php/search.php',
cache: false,
type: 'get',
data: {
id: $('input#id').val()
},
success: function (response) {
$('table#resultTable tbody').html(response);
}
});
编辑:从jQuery.ajax()的jQuery API文档中:
cache (default: true, false for dataType ‘script’ and ‘jsonp’)
标签:mysql,php,pdo
来源: https://codeday.me/bug/20191121/2048697.html