用jquery ajax后操作dom导致的ie问题
关于IE7中jquery ajax出错的问题,据说是DOM问题
情况是这样的,用ajax翻页,服务器端传回json对象,然后设置table里的数据时总是会引起$.ajax里的error:function。
但是事实上ajax是成功的,能够获取数据,只要不设置table数据,就会发现执行了success:function回调。
难道真是传说中的对DOM操作过多引起的问题?但是就20行数据,字段也不多。
参考过这边的其他几个相关帖子感觉还是找不到解决方法。
贴上代码大家帮我参考一下。有什么解决方法请不吝赐教
JS代码
function setTableData(data)
{
var table = document.getElementById("styling").getElementsByTagName("tbody")[0];
if(table)
{
for (i = 0; i < table.rows.length; i++)
{
// alert(data[i].WordID);
// alert(data[i].WordName);
// alert(data[i].Grade);
// alert(data[i].RegisteredNumber);
// alert(data[i].BasePrice);
table.rows[i].cells[0].childNodes[1].value = data[i].WordID;
table.rows[i].cells[1].childNodes[1].href = "ViewWordInfo.aspx?WordID=" + data[i].WordID;
table.rows[i].cells[1].childNodes[1].firstChild.nodeValue = data[i].WordName;
table.rows[i].cells[2].firstChild.nodeValue = data[i].Grade;
table.rows[i].cells[3].firstChild.nodeValue = data[i].RegisteredNumber;
table.rows[i].cells[4].firstChild.nodeValue = data[i].BasePrice;
table.rows[i].cells[5].childNodes[1].onclick = new Function("showUrl('ViewWordInfo.aspx?WordID=" + data[i].WordID + "')");
table.rows[i].cells[5].childNodes[3].onclick = new Function("showUrl('ModifyWord.aspx?WordID=" + data[i].WordID + "')");
}
}
}
///****获取所有词条,用于定赢,代理商,客户词条和未登录词条****/
function GetAllWords()
{
$.ajax
(
{
type: "GET",
url: "Json/WordList.aspx",
dataType: "json",
data:"flag=0" + "&pageIndex=" + currentPageIndex + "&pageSize="+ TotalPageSize,
success:function(msg)
{
//alert(msg);
setTableData(msg.Word);
document.getElementById("pageSelect").options[currentPageIndex].selected = true;
},
error:function()
{
alert("failed in word");
}
}
);
}
html代码,$$部分是模板引擎生成的内容。
<table id="styling" width="100%" border="0" cellspacing="0" cellpadding="4" class="bt">
<thead>
<tr align="left">
<th width="5%">
</th>
<th width="25%">
<b>词条</b></th>
<th width="10%">
<b>等级</b></th>
<th width="15%">
<b>注册公司数目</b></th>
<th width="15%">
底价</th>
<th width="30%">
</th>
</tr>
</thead>
<tbody>
$WordList:{<tr class="bt2">
<td>
<input type="checkbox" class="chk" name="checkbox2" value="$it.WordID$" /></td>
<td>
<a href="ViewWordInfo.aspx?WordID=$it.WordID$">$it.WordName$</a></td>
<td>
$it.Grade$</td>
<td>
$it.RegisteredNumber$</td>
<td>
$it.BasePrice$</td>
<td>
<input type="button" name="Submit3" value="详 情" onclick="window.open('ViewWordInfo.aspx?WordID=$it.WordID$','mainFrame')" />$if(User.IsAdministrator)$
<input type="button" name="Submit3" value="修 改" onclick="window.open('ModifyWord.aspx?WordID=$it.WordID$','mainFrame')" />$endif$
</td>
</tr>}$
</tbody>
</table>