J M
J M

Reputation: 1

Appending data to table is not working from ajax

I have table like below

<table class="table" id="tbl">
    <thead>
        <tr>
            <th">ID</th>
            /* some headings */
        </tr>
    </thead>
    <tbody class="tbodyAppend">
        /* need to append data here */
    </tbody>
</table>

I have a ajax to append data to the tbody

$.ajax({
    type: "POST",
    url: "AdminView.aspx/searchNECB",
    contentType: "application/json; charset=utf-8",
    data: '',
    dataType: "json",
    success: function (data) {
        console.log(data)  // data coming here in both times
        searchAppend(data.d);
    },
    error: function (msg) {
        alert("error");
    }
});

This was working fine.

Then for some need I added runat="server" to the table tag. I need this attribute to get table in serverside, but after I added this appending is not working. I get data in ajax success but append not working.

What is wrong here? Please help.

Upvotes: 1

Views: 147

Answers (1)

Ercan Peker
Ercan Peker

Reputation: 1662

runat="server" changes id of table control to "ContentPlaceHolderName_tbl". if you're accessing table with "tbl" id in searchAppend function, it cannot find it.

Upvotes: 1

Related Questions