[問題] 有關使用jQuery在刪除資料的一點疑問

看板Ajax作者 (葉慈)時間12年前 (2013/10/14 10:43), 編輯推噓1(101)
留言2則, 1人參與, 最新討論串1/1
各位高手,我的系統是Mac OS X 10.8.5的用戶,使用MacVim來當作Editor。 以下是我資料夾的狀況: /Library/WebServer/Documents/ | | --------css/ | | --------js/ | |---------try.js | | --------src/ | |---------delete.php | | --------templates/ | |---------query.php | | --------index.html 我正在練習一個簡單的範例題,但是我出現一個難以索解的問題, 希望各位可以幫忙解答。 首先,這是附圖(index.html): http://s917.photobucket.com/user/petercilee/media/001_zps8b867241.png.html?sort=3&o=0 這是一個金庸人物的資料登陸,如果按下查詢,會呼叫位於templates裡 面的query.php來列出資料結果: http://s917.photobucket.com/user/petercilee/media/002_zps8732d70b.png.html?filters[user]=137595473&filters[recent]=1&sort=1&o=0 如果移動光棒到任一個列表的話,會出現光棒,還有隱藏的垃圾桶圖示 與編輯圖示: http://s917.photobucket.com/user/petercilee/media/003_zpsd13e8e53.png.html?filters[user]=137595473&filters[recent]=1&sort=1&o=0 我想要做一個功能,是按下垃圾桶後,該資料會被刪除,然後那一行,會fadeout。 但是,我在這裡出現了一個奇怪的錯誤,就是,我的資料確認在按下垃圾 桶後,確實的被刪除了,然而畫面卻沒有任何變化.....= = 我的結構是這樣的,畫面的任何動作,寫在try.js裡面,按下query.php中 的垃圾桶後,try.js會去連delete.php,刪除完資料時再fadeout掉該行資 料。 以下是我的try.js的程式碼: $("table").find("img[class='icon_garbage']").click(function(){ var delnum = $(this).parents("tr").find("td[class='so']").text(); var string='delete_num='+delnum; $.ajax({ url:"../src/delete.php", type:"post", data:string, success: function(){ var tr = $(this).parents("tr"); tr.fadeOut('slow', function(){ $(this).remove(); }); } }) }); 以下是我的query.php的程式碼: <?php $str = 'select * from ch'; $result = mysqli_query($testlink,$str); echo '<table cellspacing="0">'; echo '<tr><td>武林編號</td><td>俠客姓名</td><td>得意招式</td><td>所屬門派</td></tr>'; while ($row = mysqli_fetch_array($result)) { echo '<tr><td id="serial" class="so">'.$row[num].'</td><td>'.$row[name].'</td><td>'.$row[gonfu].'</td><td>'.$row[locate].'</td><td class="animated pulse" style="width:30px"><img class="icon_garbage" src="../img/garbage.png"></td><td class="animated pulse" style="width:20px"><img class="icon_edit" src="../img/edit.png"></td>'; } echo '</table>'; ?> 以下是我的delete.php的程式碼: <?php include ("serverlink.php"); include ("vars.php"); $str="DELETE FROM ch WHERE num =".$_POST['delete_num']; mysqli_query($testlink,$str); ?> 抱歉了,請各位可以幫忙解惑,在此先謝了.... m(_ _)m -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 114.39.90.51

10/19 23:06, , 1F
var tr = $(this).parents("tr");
10/19 23:06, 1F

10/19 23:07, , 2F
這行的this會指向到ajax response,這應該不是你要的結果
10/19 23:07, 2F
文章代碼(AID): #1IMrexvy (Ajax)
文章代碼(AID): #1IMrexvy (Ajax)