jquery + ajax +smarty+php 無重新整理刪除資料代碼

來源:互聯網
上載者:User

jquery + ajax +smarty+php教程 無重新整理刪除資料代碼
寫個js:view sourceprint?01

02 function delItem (id) { 

03 $.get('delete.php?id='+id,null,function (msg) {//ajax請求,請求後執行下面<SPAN class=t_tag onclick=tagshow(event) href="tag.php?name=%B4%FA%C2%EB">代碼</SPAN> 

04 if ('1'==msg) {//返回1表示成功 

05 $('#t'+id).remove();//把id為txx 的表格刪除 

06 } else {//否則彈出錯誤資訊 

07 alert(msg); 

08 } 

09   

10 }); 

11 } 


刪除連結改成 href="javascript教程:delItem('<!--{$item.id}-->')" delete.php的修改就是把錯誤語句改成直接輸出就行了。 OK完成。 index.tpl :view sourceprint?01 <!DOCTYPE <SPAN class=t_tag onclick=tagshow(event) href="tag.php?name=html">html</SPAN> PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">   

02 <html <SPAN class=t_tag onclick=tagshow(event) href="tag.php?name=xml">xml</SPAN>ns="http://www.w3.org/1999/xhtml">   

03 <head>   

04 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />   

05 <title>所有留言</title>   

06 <link rel="stylesheet" type="text/css教程" href="style.css" media="all" />   

07   

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

09 </head>   

10 <body>   

11 <!--{if $smarty.<SPAN class=t_tag onclick=tagshow(event) href="tag.php?name=session">session</SPAN>.username}-->   

12 Welcome:<!--{$smarty.session.username}-->   

13 <a href="logout.php">退出</a>   

14 <!--{else}-->   

15 <a href="login.php">登入</a>   

16 <a href="reg.php">註冊</a>   

17 <!--{/if}-->   

18 <a href="add.php">發表留言</a>   

19 <!--{foreach from=$gblist item=item}-->   

20 <table id="t<!--{$item.id}-->" width="700" border="0" cellspacing="0" cellpadding="0" class="tb">   

21   <tr>   

22     <td class="bg"><b>[<!--{$item.username}-->]</b> 發表於:<!--{$item.insert_time}--></td>   

23   </tr>   

24   <tr>   

25     <td><!--{$item.content}-->   

26     <br />   

27 <!--{if $item.user_file}-->   

28     附件:<a target="_blank" href="uploads/<!--{$item.user_file}-->"><!--{$item.user_file}--></a>   

29 <!--{/if}-->   

30 </td>   

31   </tr>   

32   <tr>   

33     <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>   

34   </tr>   

35 </table>   

36 <!--{/foreach}-->   

37 <!--{$pagePanel}-->   

38 <script>   

39 function delItem (id) {   

40     $.get('delete.php?id='+id,null,function (msg) {   

41         if ('1'==msg) {   

42             $('#t'+id).remove();   

43         } else {   

44             alert(msg);   

45         }   

46   

47     });   

48 }   

49 </script>   

50 </body>   

51 </html>
delete.php :view sourceprint?01 <?php   

02 require('common.php');   

03 // <SPAN class=t_tag onclick=tagshow(event) href="tag.php?name=%B2%E9%D1%AF">查詢</SPAN>出留言資訊   

04 $q = $query->query('select * from gb_content where id='.intval($_GET['id']));   

05 $rs = $query->fetch_array($q);   

06 $error = array();   

07 if ($rs['user_id']!=intval($_SESSION['user_id'])) {// 判斷user_id是否相同   

08     $error = '該資訊你不能刪除,只能刪除自己發布的';   

09 }   

10 if (!$error) {   

11     $query->query('delete from gb_content where id='.intval($_GET['id']));//刪除語句   

12     if ($rs['user_file']) {//刪除附件   

13         @unlink('uploads/'.$rs['user_file']);   

14     }   

15     echo 1;//表示成功   

16 } else {   

17     echo $error;   

18 }   

19 ?>

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.