简体   繁体   English

jQuery在ajax发布结果上隐藏表行

[英]JQuery Hide table row on ajax post result

I have the following code. 我有以下代码。 It is supposed to hide a row on success of the onClick function. 它应该在onClick函数成功时隐藏一行。 Unfortunately it just does not hide anything. 不幸的是,它只是没有隐藏任何东西。 I have seen this question on SO, tried the solutions with no effect. 我在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>

The alert on success shows up, so the code is being executed but I never see anything disappear or even change color. 显示成功警告,因此代码正在执行,但我从未看到任何东西消失甚至改变颜色。 All the commented variants have been tried without success. 所有已评论的变体都已尝试成功。 There must be some basic misunderstanding .. 必须有一些基本的误解..

your selector is wrong. 您的选择器有误。 onclick = "deleteMsg($('#row1') , )" you forgot the little '#' onclick = "deleteMsg($('#row1') ,)”您忘记了onclick = "deleteMsg($('#row1')的'#'

You just need to add # in your Jquery selector : 您只需要在Jquery选择器中添加#

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

And then, you can use row.hide(); 然后,您可以使用row.hide(); in your success function to hide the block (and not $(row).hide(); like you tried) 在您的success函数中隐藏块(而不是$(row).hide();就像您尝试过的那样)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM