[英]php do not fetch new data from database after adding item
I working on a very simple form project, I send items using ajax and save them on the database using PHP insert
query, then by clicking a button I fetch data using ajax from another PHP file using SELECT
query, the problem is when I want to get new data the PHP query doesn't update data and it returns old data if I check the file whit out using ajax and I put the URL like mysite.com/getdata.php
it still returns old data and I have to refresh this page until it fetches new data, I don't have any error or warning in my javascript code or PHP and I have no idea why it doesn't get new data whit new request and I have to refresh the URL t I working on a very simple form project, I send items using ajax and save them on the database using PHP insert
query, then by clicking a button I fetch data using ajax from another PHP file using SELECT
query, the problem is when I want to get new data the PHP query doesn't update data and it returns old data if I check the file whit out using ajax and I put the URL like mysite.com/getdata.php
it still returns old data and I have to refresh this page在它获取新数据之前,我的 javascript 代码或 PHP 中没有任何错误或警告,我不知道为什么它没有收到新请求的新数据,我必须刷新 ZE6B391A8D2C4D45903DZtA ill fetches new data.生病获取新数据。
It worked correctly local I see this bug when I upload my code to the server当我将代码上传到服务器时,它在本地正常工作我看到了这个错误
My getdata.php
file code:我的getdata.php
文件代码:
<?php
$servername = "localhost";
$username = "projectform";
$password = "jtq*o2ZL7qBPt_HS";
$dbname = "projectform";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
$responseData = json_encode(array(
"status" => $status,
"message" => "Connection failed: " . $conn->connect_error,
"data" => null,
));
die($responseData);
}
$sql = "SELECT * FROM form_data";
$result = $conn->query($sql);
$data = array();
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
$data[] = array(
'id' => $row["id"],
'Title' => $row["title"],
'address' => $row["address"],
'photo' => $row["p_date"],
'phone' => $row["phone"],
'detail' => $row["detail"],
'create' => $row["created_at"],
'status' => $row["status"],
);
}
$status = "success";
$message = "";
$response = $data;
} else {
$data = null;
$status = "error";
$message = "NO data found.";
}
$conn->close();
$responseData = json_encode(array(
"status" => $status,
"message" => $message,
"data" => $response,
));
die($responseData);
If you are using pure PHP, you can try to disable browser cache like this:如果您使用的是纯 PHP,您可以尝试禁用浏览器缓存,如下所示:
header("Expires: Thu, 01 Jan 1970 00:00:00 GMT");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Cache-Control: no-store, no-cache, must-revalidate, max-age=0");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
header("Connection: close");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.