簡體   English   中英

jQuery在ajax發布結果上隱藏表行

[英]JQuery Hide table row on ajax post result

我有以下代碼。 它應該在onClick函數成功時隱藏一行。 不幸的是,它只是沒有隱藏任何東西。 我在SO上看到了這個問題,嘗試了無效的解決方案。

<script type="text/javascript">
    function deleteMsg(row,msgId) {
        //window.alert("deleteMsg(" + msgId + ")");
        $.ajax({
            type: "POST",
            url: "http://localhost:8080/ArcheryScoresV3/profile.jsp",
            data: { cmd:"delete_msg",
                s_token:"dn1ejdmj0dkmgerbm481adkjt0",
                message: msgId },  
            dataType: "json",
            success: function(msg, status, jqXHR){
                if(msg.success == "true") {
                window.alert("successfull, hiding " + row.id);
                //$(this).parents("tr").hide();
                //$(row).hide();
                row.css("background-color", "red");
            } else {
                window.alert("unsuccessfull");
            }
            },            
            error: function(xhr,status,error){
                window.alert("error, status:" + error);
            }
        });
    }
    </script>
     <tr id="row1">
        <td><span onClick="deleteMsg($('row1'),'0ed71375-226e-49ae-aa14-00fbb1f7ed11');" 
                  class="glyphicon glyphicon-trash">
            </span>
        </td>
    </tr>

顯示成功警告,因此代碼正在執行,但我從未看到任何東西消失甚至改變顏色。 所有已評論的變體都已嘗試成功。 必須有一些基本的誤解..

您的選擇器有誤。 onclick = "deleteMsg($('#row1') ,)”您忘記了onclick = "deleteMsg($('#row1')的'#'

您只需要在Jquery選擇器中添加#

<tr id="row1">
    <td>
        <span onClick="deleteMsg($('#row1'),'0ed71375-226e-49ae-aa14-00fbb1f7ed11');" 
            class="glyphicon glyphicon-trash">
        </span>
   </td>
</tr>

然后,您可以使用row.hide(); 在您的success函數中隱藏塊(而不是$(row).hide();就像您嘗試過的那樣)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM