亲爱的,我在 onload body 上调用了一个 javascript 函数
<body onload="loadLeads()">
此函数从数据库加载潜在客户信息并将其显示在表格中。问题是当用户按下删除按钮从表中删除潜在客户时。该函数正确运行并从数据库中删除潜在客户。但是,尽管 deletelead 函数重新加载了在加载页面时调用 loadLeads() 的页面,该页面应该显示新的潜在客户,而没有删除的潜在客户。但是删除的一个又显示了!虽然它从数据库中删除了!!我怎样才能正确运行它?每次都要删除浏览器的缓存,强制代码正常运行!!请问我该怎么做?
这是删除的javascript代码
function deleteLead(id)
{
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function()
{
if (this.readyState == 4 && this.status == 200)
{
location.reload();
}
}
xmlhttp.open("GET", "deletelead.php?id="+id, true);
xmlhttp.send();
}
这是在 HTML 中调用的脚本
<script src="https://example.net/js/loadLeads.js?version=' + Math.floor(Math.random() * 100) + '"\><\/script>'"></script>
这是 loadleads 函数 javascript
function loadLeads()
{
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function()
{
if (this.readyState == 4 && this.status == 200)
{
LeadsInfo = JSON.parse(this.responseText);
LeadsInfoCount = LeadsInfo.length;
DrawLeadsTable();
}
}
xmlhttp.open("GET", "LoadLeads.php", true);
xmlhttp.send();
}
这是 LoadLeads.php
<?php
require "conn.php";
$SelectSQL = "SELECT * FROM leads";
$result = $conn->query($SelectSQL);
$ECount = $result->num_rows;
if ($ECount != 0 )
{
$FinalArr = array();
$count =0;
while($row1 = $result->fetch_assoc())
{
$id = $row1["id"];
$name = $row1["name"];
$email = $row1["email"];
$mob = $row1["mob"];
$country = $row1["country"];
$comefrom = $row1["comefrom"];
$time = $row1["time"];
$qulified = $row1["qulified"];
$landingpage = $row1["landingpage"];
$myArr = array($id,$name,$email, $mob,$country,$comefrom,$time,$qulified,$landingpage);
$FinalArr[$count] = array();
$FinalArr[$count] = $myArr;
$count++;
$UserData = json_encode($FinalArr,JSON_UNESCAPED_UNICODE);
}
}
mysqli_close($conn);
echo $UserData;
?>
在 xmlhttp.send(); 之前添加这个
xmlhttp.setRequestHeader("Cache-Control", "no-cache, no-store, must-revalidate");
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句