【发布时间】:2012-09-12 08:32:08
【问题描述】:
我有三页:
1)index.php(从select.php获取结果并放入div#result)
2)select.php(循环到 MySQL 的表中)
3)delete.php(获取user_id作为参数并从MySQL的表中删除)。
我的目标是:用户点击删除后!显示更新的结果(更改/删除后)
来自 MySQL 的表
我的问题是我不知道如何告诉 jQuery:listen process delete.php?id=123 & then
在 index.php 中重新加载 select.php 而不重定向到 delete.php
所以用户实际上看不到发生了什么或看不到他被重定向到
另一个页面。
index.php
<html>
<title>a</title>
<head>
<script type="text/javascript" src="jquery-1.8.0.js"></script>
<script type="text/javascript">
$(function() {
$('#result').load('select.php');
});
</script>
</head>
<body>
<div id="result"></div>
</body>
</html>
select.php
<?php
$con = mysql_connect("localhost","root","123");
if (!$con) { die('Could not connect: '); }
mysql_select_db("test", $con);
$result = mysql_query("select * from users");
while($rs3 = mysql_fetch_array($result)) {
echo $rs3["user_email"]." ".$rs3["user_name"]." ";
echo "<a href=delete.php?id=".$rs3[user_id].">Delete</a>";
echo "<br />";
}
?>
删除.php
<?php
$con = mysql_connect("localhost","root","123");
if (!$con) { die('Could not connect: '); }
mysql_select_db("test", $con);
$id = mysql_escape_string($_GET["id"]);
$delete = "delete from users where user_id='{$id}'";
@mysql_query($delete);
?>
谢谢。
【问题讨论】:
-
你在正确的轨道上。您需要做的是:单击“删除”按钮时,使用 ajax(jquery 很容易)调用
delete.php并删除表中的行,其中单击了“删除”按钮.这样您就不需要重新加载表格。当然,只有在收到'delete.php'的成功响应后,您才需要删除该行 -
@eawedat 查看我的答案编辑。