0

I am having an HTML table and I need to change it contents.

 <div id='adf'>
   <table id='tbl1' runat='server' >
     <tr><td></td></tr>
   </table>
 </div>

I am changing the contents using a jQuery Ajax and the problem is that I am accessing the same table with same name after that. So I am changing the HTML content and inserts new HTML of a table will adds a new table. So I need to remove the table rows and add the results to the table. So there will be no change in the contents. Thanks in advance.

2
  • It would help if you post your ajax code. The answer will depend on the content type of your ajax call. Commented Oct 6, 2010 at 9:24
  • I got the solution using append().Thanks for your support Commented Oct 15, 2010 at 6:22

4 Answers 4

2

If I understand you correctly, use the html() function to change the contents after you've run the ajax call.

As a efficiency tip, make sure you load all the changes into a string and just call html() once at the end. Otherwise, you'll find your page to be extremely slow.

If you are just adding new rows, use append(). http://api.jquery.com/append/

It shouldn't matter that the table has the same name. Just grab it by its identifier.

Sign up to request clarification or add additional context in comments.

2 Comments

thanks jng5 let me check.Can I use $('#abc').html(res) ? where res is ajax result ??
It depends, what does res look like? If it has <table> etc. included, should work. If it's just rows, use $('#tbl1').html(res);
1
 $('#tbl1').html($('#tbl1').html() + "<tr><td>this is new row</td></tr>")

Comments

0

Look at this post

http://nithuan.wordpress.com/2010/08/30/dynamically-addind-table-row-using-jquery/

3 Comments

$(‘ tblDoc tr:last’).after( “<tr>”+“<td style=’width:150px;’><span>” + getTextBoxValue(‘<%=txtDocName.ClientID %>’) + “</span></td><td style=’width: 150px’>” + getTextBoxValue(‘<%=txtDocNo.ClientID %>’) + “</td><td style=’width: 150px’>” + getTextBoxValue(‘<%=txtIssuedBy.ClientID %>‘) + “</td><td style=’width: 150px’>” + getTextBoxValue(‘<%=txtIssuedDate.ClientID %>’) + “</td><td style=’width: 150px’>” + getTextBoxValue(‘<%=txtRenewalDate.ClientID %>’) + “</td></tr>” ); what this is to add a new row after the particular row
What I need is to change the entire row with the data from server?
you may use the $ajax methode of jquery
0

You need to use the ClientID of the table, because it is runat="server"

$.get('ajax/tbl1.html', function(data) {
     $('#' + <%= tbl1.ClientID %>).html(data);
});

tbl1.html would contain the replacement rows. You could change this to an aspx page or php or a webservice that returns html.

Here is a sample JQuery AJAX call that has worked for me in the past:

            jQuery.ajax({ type: "POST",
                url: "MyWebService.asmx/GetHtml",
                data: "{'Id' :'" + tableId + "'}", //may not be necessary in your case
                dataType: "json",
                contentType: 'application/json; charset=utf-8',
                success: function(json) {
                    var result = eval("(" + json.d + ")");
                    jQuery('#' + <%= tbl1.ClientID %>).html(result.value);
                }
             });

Note the use of JSON and the call to eval.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.