1
我有一個php代碼,當用戶刪除一條記錄時會發出警報,但它會在提醒時刷新頁面,然後背景頁面變爲空白,這看起來很煩人。我怎樣才能不刷新頁面?以下是我的示例代碼,名稱爲deleteuser.php。提醒用戶不刷新頁面中的PHP
<?
include 'mysqlcon.php'; // my connection credentials to php
$postudel = $_POST['enterudel'];
if($postudel!="")
{
$sqldel = "DELETE FROM User WHERE UserName = '$postudel'";
$getdel = mysql_query($sqldel,$con) or die(mysql_error());
echo "<script language='javascript'>";
echo "alert('User $postudel successfully deleted.');";
echo "</script>";
}
?>
<html>
<head>
<title>Delete User</title>
<SCRIPT language=JavaScript>
function deluser()
{
var r=confirm("Are you sure you want to do this?");
if (r==true)
{
var objsel = document.getElementById("duser");
var udel = objsel.options[objsel.selectedIndex].id;
document.formdel.enterudel.value = udel;
document.formdel.submit();
}
else
return false;
}
</script>
</head>
<body>
<table width="50%" align="left">
<tr><td width="50%" colspan="2">
<big>Delete User:</big>
</td></tr>
<tr><td width="25%">
Username:
<SELECT id="duser">
<option>Choose One</option>
<?
$sqldu=mysql_query("SELECT UserName from User");
while($row=mysql_fetch_array($sqldu))
{
echo "<OPTION ID=".$row['UserName'];
echo ">".$row['UserName']."</OPTION>";
}
?>
</SELECT>
</td>
<td width="25%">
<input type="button" value="Delete" id="delete" onClick="deluser()">
</td></tr>
</table>
<form name="formdel" action="../deleteuser.php" method="post">
<input type="hidden" name="enterudel" value="<?=$postudel?>">
</form>
</body>
</html>
AJAX =沒有刷新的東西。 –
嘗試在http://api.jquery.com/jQuery.ajax/上使用jquery ajax/ – Habibillah