ajax - jquery replace table rows with new data -


I am trying to replace the table with new data received through ajax. For the first time just works just fine But then the rows are added instead of replacing them. So I end up with duplicate rows here. I have some code here

  success: function (data) {$ ("# featured_listing_tbody"). Children ('tr: not (: first)') .remove (); Counter = 1; $ .eec (data, function (i, val) {newPropertyRows + = '& lt; tr & gt;'; $ .EEC (val, function (key, info) {var skip = false; if (key == " Id ") {id = information; new property everyday = ''; leave = true;} if (key ==" thumb ") {info = '& lt; img width =" 100px "src = upload / properties /' + id + '/ Thumbs_' + Info + '/ & gt;'; newPropertyRows + = '& lt; td class = "call' + counter + '" & gt; & lt; a href = "/ featured.php? Prop = '+ + Id +' "& gt; '+ info +' & lt; / a & gt; & lt; / td & gt; '; skip = true; counter ++;} if (skip == incorrect) {NewPropertyRows + = '& lt; td class = "col' + +" ">   

Thanks to any thoughts or insights anyone can have this problem for

Probably the problem is not in the part of the code that you posted. For example, in the current code you use the + = variable with the newPropertyRows variable can you reset it to empty string before every AJAX call

Well I think you do not call $ ("# featured_listing_tbody"). Children ('tr: not (: first)') .remove () In the beginning success handler because you use $ ("#ty_listing_tbody"). Html (newPropertyRows); will later overwrite the entire body of the table.

Comments