PHP+ajax 无刷新删除数据
delete data
No refresh
首先本例基于留言本整理版修改。无刷新删除数据 (PHP)我们使用了jquery.js来实现ajax和dom删除
首先本例基于留言本整理版修改。
我们使用了jquery.js来实现ajax和dom删除
首先加入
代码如下:
给table加个
代码如下:
id="t"
写个js:
代码如下:
<script> <BR>function delItem (id) { <BR>$.get('delete.php?id='+id,null,function (msg) {//ajax请求,请求后执行下面代码 <BR>if ('1'==msg) {//返回1表示成功 <BR>$('#t'+id).remove();//把id为txx 的表格删除 <BR>} else {//否则弹出错误信息 <BR>alert(msg); <BR>} <BR>}); <BR>} <BR></script>
删除链接改成 href="javascript:delItem('')"
delete.php的修改就是把错误语句改成直接输出就行了。
OK完成。
index.tpl :
代码如下:
Welcome:
退出
登录
注册
发表留言
[] 发表于: |
附件: |
修改 删除 |
<script> <BR>function delItem (id) { <BR>$.get('delete.php?id='+id,null,function (msg) { <BR>if ('1'==msg) { <BR>$('#t'+id).remove(); <BR>} else { <BR>alert(msg); <BR>} <BR>}); <BR>} <BR></script>
delete.php :
代码如下:
require('common.php');
// 查询出留言信息
$q = $query->query('select * from gb_content where id='.intval($_GET['id']));
$rs = $query->fetch_array($q);
$error = array();
if ($rs['user_id']!=intval($_SESSION['user_id'])) {// 判断user_id是否相同
$error = '该信息你不能删除,只能删除自己发布的';
}
if (!$error) {
$query->query('delete from gb_content where id='.intval($_GET['id']));//删除语句
if ($rs['user_file']) {//删除附件
@unlink('uploads/'.$rs['user_file']);
}
echo 1;//表示成功
} else {
echo $error;
}
?>
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article
R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
1 months ago
By 尊渡假赌尊渡假赌尊渡假赌
How Long Does It Take To Beat Split Fiction?
4 weeks ago
By DDD
R.E.P.O. Save File Location: Where Is It & How to Protect It?
1 months ago
By DDD
Two Point Museum: All Exhibits And Where To Find Them
1 months ago
By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)
