最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

PHP+ajax 無(wú)刷新刪除數(shù)據(jù)

 更新時(shí)間:2010年02月20日 12:26:04   作者:  
首先本例基于留言本整理版修改。無(wú)刷新刪除數(shù)據(jù) (PHP)我們使用了jquery.js來(lái)實(shí)現(xiàn)ajax和dom刪除
首先本例基于留言本整理版修改。
我們使用了jquery.js來(lái)實(shí)現(xiàn)ajax和dom刪除
首先加入
復(fù)制代碼 代碼如下:

<script type="text/javascript" src="lib/jquery.js"></script>

給table加個(gè)
復(fù)制代碼 代碼如下:

id="t<!--{$item.id}-->"

寫(xiě)個(gè)js:
復(fù)制代碼 代碼如下:

<script>
function delItem (id) {
$.get('delete.php?id='+id,null,function (msg) {//ajax請(qǐng)求,請(qǐng)求后執(zhí)行下面代碼
if ('1'==msg) {//返回1表示成功
$('#t'+id).remove();//把id為txx 的表格刪除
} else {//否則彈出錯(cuò)誤信息
alert(msg);
}
});
}
</script>

刪除鏈接改成 href="javascript:delItem('<!--{$item.id}-->')"
delete.php的修改就是把錯(cuò)誤語(yǔ)句改成直接輸出就行了。
OK完成。
index.tpl :
復(fù)制代碼 代碼如下:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>所有留言</title>
<link rel="stylesheet" type="text/css" href="style.css" media="all" />
<script type="text/javascript" src="lib/jquery.js"></script>
</head>
<body>
<!--{if $smarty.session.username}-->
Welcome:<!--{$smarty.session.username}-->
<a href="logout.php">退出</a>
<!--{else}-->
<a href="login.php">登錄</a>
<a href="reg.php">注冊(cè)</a>
<!--{/if}-->
<a href="add.php">發(fā)表留言</a>
<!--{foreach from=$gblist item=item}-->
<table id="t<!--{$item.id}-->" width="700" border="0" cellspacing="0" cellpadding="0" class="tb">
<tr>
<td class="bg"><b>[<!--{$item.username}-->]</b> 發(fā)表于:<!--{$item.insert_time}--></td>
</tr>
<tr>
<td><!--{$item.content}-->
<br />
<!--{if $item.user_file}-->
附件:<a target="_blank" href="uploads/<!--{$item.user_file}-->"><!--{$item.user_file}--></a>
<!--{/if}-->
</td>
</tr>
<tr>
<td align="right"><!--{if $item.user_id==$smarty.session.user_id}--><a href="add.php?id=<!--{$item.id}-->">修改</a> <a href="javascript:delItem('<!--{$item.id}-->')">刪除</a><!--{/if}--></td>
</tr>
</table>
<!--{/foreach}-->
<!--{$pagePanel}-->
<script>
function delItem (id) {
$.get('delete.php?id='+id,null,function (msg) {
if ('1'==msg) {
$('#t'+id).remove();
} else {
alert(msg);
}
});
}
</script>
</body>
</html>

delete.php :
復(fù)制代碼 代碼如下:

<?php
require('common.php');
// 查詢(xún)出留言信息
$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 = '該信息你不能刪除,只能刪除自己發(fā)布的';
}
if (!$error) {
$query->query('delete from gb_content where id='.intval($_GET['id']));//刪除語(yǔ)句
if ($rs['user_file']) {//刪除附件
@unlink('uploads/'.$rs['user_file']);
}
echo 1;//表示成功
} else {
echo $error;
}
?>

相關(guān)文章

最新評(píng)論

潍坊市| 平果县| 肇庆市| 仁布县| 新田县| 闸北区| 准格尔旗| 琼海市| 通辽市| 陇南市| 铜梁县| 昌乐县| 嘉义市| 乌拉特后旗| 仁化县| 武乡县| 剑河县| 阳江市| 上栗县| 锡林浩特市| 灌阳县| 阳泉市| 永兴县| 江达县| 宿迁市| 尼玛县| 河西区| 额济纳旗| 礼泉县| 南平市| 伽师县| 石台县| 郴州市| 微博| 邢台市| 麦盖提县| 定州市| 金昌市| 南和县| 大悟县| 千阳县|