Thomas
Thomas

Reputation: 371

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 ..

Upvotes: 1

Views: 1556

Answers (2)

Magicprog.fr
Magicprog.fr

Reputation: 4100

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)

Upvotes: 0

Amit
Amit

Reputation: 457

your selector is wrong. onclick = "deleteMsg($('#row1'), )" you forgot the little '#'

Upvotes: 1

Related Questions