简体   繁体   中英

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. Unfortunately it just does not hide anything. I have seen this question on SO, tried the solutions with no effect.

<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 '#'

You just need to add # in your Jquery selector :

<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(); in your success function to hide the block (and not $(row).hide(); like you tried)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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