数据库删除后页面不刷新 怎么实现点击删除自动刷新!
主页面<html><head><title>删除数据</title><scripttype="text/javascript">functionGetXmlHttpReq...
主页面
<html>
<head>
<title>删除数据</title>
<script type="text/javascript">
function GetXmlHttpRequest()
{
var xmlHttp=null;
try
{
xmlHttp = new XMLHttpRequest(); //对于Firefox等浏览器
}
catch(e)
{
try
{
xmlHttp = new ActiveXObject("Msxml2.XMLHTTP"); //对于IE浏览器
}
catch (e)
{
try
{
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
}
catch(e)
{
xmlHttp = false;
}
}
}
return xmlHttp;
}
function sendRequest()
{
var del1 = document.getElementById("del").value;
if((del1 == null) || (del1 == ""))
return;
xmlHttp = GetXmlHttpRequest();
if(xmlHttp == null)
{
alert("浏览器不支持XmlHttpRequest!");
return;
}
var url="delete.php";
url = url + "?del=" + del1;
xmlHttp.open("GET", url, true);
xmlHttp.onreadystatechange = updatePage;
xmlHttp.send(null); //发送请求
}
function updatePage()
{
if(xmlHttp.readyState == 4)
{
document.getElementById("userinfo").value = xmlHttp.responseText;
}
}
</script>
<body>
<div id="userinfo">
<?php
$link=mysql_connect('localhost','root','')or die("Unable to connect to Mysql");
mysql_select_db("testdrive",$link)or die("Unable to connnect to database");
$result=mysql_query("SELECT * from user",$link);
echo "<table border='1' bgcolor='yellow' align='center' width='400' cellspacing='0' cellpadding='0' id='delete' >";
echo "<th align = 'center'>id</th>";
echo "<th align = 'center'>name</th>";
echo "<th align = 'center'>day</th>";
echo "<th align = 'center'>del</th>";
while ($row = mysql_fetch_array($result)){
echo "<tr> \n";
$id1=$row["id"];
echo "<td align ='center'>$id1</td>";
echo "<td align = 'center'>{$row['name']}</td>";
$day1=$row["day"];
$day2=substr($day1,0,10);
echo "<td align = 'center'>$day2</td> <br> </n></td>";
}
echo "<td ><button onClick='sendRequest()' name='sc'>删除</button><input type='text' id='del' /></td>";
echo "</tr> \n";
echo "</table>\n";
?>
<a href="load.php">返回</a>
</div>
</body>
</html>
删除页面
<?php
$link=mysql_connect('localhost','root','')or die("Unable to connect to Mysql");
mysql_select_db("testdrive",$link)or die("Unable to connnect to database");
$del=mysql_query("delete from user where id='".$_GET['del']."'",$link);
?>
最好是用ajax 实现无刷新删除! 展开
<html>
<head>
<title>删除数据</title>
<script type="text/javascript">
function GetXmlHttpRequest()
{
var xmlHttp=null;
try
{
xmlHttp = new XMLHttpRequest(); //对于Firefox等浏览器
}
catch(e)
{
try
{
xmlHttp = new ActiveXObject("Msxml2.XMLHTTP"); //对于IE浏览器
}
catch (e)
{
try
{
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
}
catch(e)
{
xmlHttp = false;
}
}
}
return xmlHttp;
}
function sendRequest()
{
var del1 = document.getElementById("del").value;
if((del1 == null) || (del1 == ""))
return;
xmlHttp = GetXmlHttpRequest();
if(xmlHttp == null)
{
alert("浏览器不支持XmlHttpRequest!");
return;
}
var url="delete.php";
url = url + "?del=" + del1;
xmlHttp.open("GET", url, true);
xmlHttp.onreadystatechange = updatePage;
xmlHttp.send(null); //发送请求
}
function updatePage()
{
if(xmlHttp.readyState == 4)
{
document.getElementById("userinfo").value = xmlHttp.responseText;
}
}
</script>
<body>
<div id="userinfo">
<?php
$link=mysql_connect('localhost','root','')or die("Unable to connect to Mysql");
mysql_select_db("testdrive",$link)or die("Unable to connnect to database");
$result=mysql_query("SELECT * from user",$link);
echo "<table border='1' bgcolor='yellow' align='center' width='400' cellspacing='0' cellpadding='0' id='delete' >";
echo "<th align = 'center'>id</th>";
echo "<th align = 'center'>name</th>";
echo "<th align = 'center'>day</th>";
echo "<th align = 'center'>del</th>";
while ($row = mysql_fetch_array($result)){
echo "<tr> \n";
$id1=$row["id"];
echo "<td align ='center'>$id1</td>";
echo "<td align = 'center'>{$row['name']}</td>";
$day1=$row["day"];
$day2=substr($day1,0,10);
echo "<td align = 'center'>$day2</td> <br> </n></td>";
}
echo "<td ><button onClick='sendRequest()' name='sc'>删除</button><input type='text' id='del' /></td>";
echo "</tr> \n";
echo "</table>\n";
?>
<a href="load.php">返回</a>
</div>
</body>
</html>
删除页面
<?php
$link=mysql_connect('localhost','root','')or die("Unable to connect to Mysql");
mysql_select_db("testdrive",$link)or die("Unable to connnect to database");
$del=mysql_query("delete from user where id='".$_GET['del']."'",$link);
?>
最好是用ajax 实现无刷新删除! 展开
4个回答
展开全部
JS window.reload()
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询