首先本例基于留言本整理版修改。无刷新删除数据 (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;
}
?>

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

Hot Tools

Zend Studio 13.0.1
Powerful PHP integrated development environment

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

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

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft
