I need to replace a tbody with new Html using the jQuery below. The .empty() function hangs when the Html is above 1Mb.
$("#searchForm").submit(function (event) {
event.preventDefault();
//$("#myTable tbody").empty();
$.post($(this).attr('action'), $(this).serialize(), function (data) {
//$("#myTable tbody").html(data);
replaceTableBody("thebody", data);
});
});
I’m not worried if it’s a tricky solution, I just want it to work…
I tried this but could not get it to work: replacehtml-for-when-innerhtml-dogs-you-down.
It only needs to work in IE.
EDIT
var replaceTableBody = function(tbodyId, html){
var temp = document.createElement('div');
temp.innerHTML = '<table><tbody id="thebody">'+html;
var tb = document.getElementById(tbodyId);
tb.parentNode.replaceChild(temp.firstChild.firstChild, tb);
temp = null;
};
i have done this before. you must not use jquery if you want this to be faster.
I wrote a long blog post about this and how its done, its long so i will not paste it here, just link it:
http://notetodogself.blogspot.com/2009/08/javascript-insert-table-rows-table-body.html
The reason you must not use jquery is that jquery does certain things once you pass text into .html(), like search for scripts, execute them, fix certain things etc. this is usually a good thing, but its not a good thing with 1mb of text on IE.