用jquery ajax后操作dom导致的ie问题

learnerkk 2007-09-07 10:29:20
关于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>
...全文
360 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
meiZiNick 2008-05-01
  • 打赏
  • 举报
回复
支持搂主,收藏
knowledge_Is_Life 2008-05-01
  • 打赏
  • 举报
回复
都是很好的建议! 值得学习
live_7sky 2008-04-24
  • 打赏
  • 举报
回复
但是事实上ajax是成功的,能够获取数据,只要不设置table数据,就会发现执行了success:function回调。

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 + " ') ");


这个地方的问题了, 方法错了,他报了 什么错误 ???????

52,797

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 Ajax
社区管理员
  • Ajax
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧