我有三页:
1)index.PHP(从select.PHP获取结果并将它们放入div#results)
3)delete.PHP(获取user_id作为参数并从MysqL的表中删除它).
来自MysqL的表
我的问题是我不知道如何告诉jQuery:listen process delete.PHP?id = 123&然后
在保留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 />";
}
?>
delete.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调用链接.例如:
<script type="text/javascript">
$(function() {
function refreshContent(){
$('#result').load('select.PHP');
}
$('#result').on('click','a',function(event){
// prevent going by link `href`
event.preventDefault();
// get deleting row id
var ids = $(this).data('ids');
// make AJAX call for delete
$.get("delete.PHP", { id: ids},function(data){
// on success - refresh tcontent
refreshContent();
});
return false;
});
// making content load on start
$(document).ready(function(){
refreshContent();
});
});
</script>
echo "<a href='delete.PHP?id=".$rs3[user_id]."' data-ids='".$rs3[user_id]."'>Delete</a>";
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。