Jquery + ajax + smarty + php: no refreshing data deletion code

Source: Internet
Author: User

Jquery + ajax + smarty + php
Write js: view sourceprint? 01

02 function delItem (id ){

03 $. get ('delete. php? Id = '+ id, null, function (msg) {// ajax request. After the request, run the following <SPAN class = t_tag onclick = tagshow (event) href = "tag. php? Name = % B4 % FA % C2 % EB "> Code </SPAN>

04 if ('1' = msg) {// 1 indicates success

05 $ ('# t' + id). remove (); // Delete the table whose id is txx

06} else {// otherwise, an error message is displayed.

07 alert (msg );

08}

09

10 });

11}


Delete link to href = "javascript Tutorial: delItem ('<! -- {$ Item. id} --> ') "Modify delete. php to change the error statement to direct output. 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

03

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

05 <title> all messages </title>

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

07

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

09

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"> quit </a>

14 <! -- {Else} -->

15 <a href = "login. php"> log on </a>

16 <a href = "reg. php"> register </a>

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

18 <a href = "add. php"> post a message </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> posted on: <! -- {$ Item. insert_time} --> </td>

23 </tr>

24 <tr>

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

26 <br/>

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

28 attachment: <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} --> "> modify </a> <a href =" javascript: delItem ('<! -- {$ Item. id} --> ') "> Delete </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
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 "> query </SPAN> outgoing message

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']) {// judge whether the user_id is the same

08 $ error = 'you cannot delete this information. You can only delete your own release ';

09}

10 if (! $ Error ){

11 $ query-> query ('delete from gb_content where id = '. intval ($ _ GET ['id']); // delete a statement

12 if ($ rs ['user _ file']) {// Delete the attachment

13 @ unlink ('uploads/'. $ rs ['user _ file']);

14}

15 echo 1; // success

16} else {

17 echo $ error;

18}

19?>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.