为什么当 IE8 关闭时我的 COMET 控件会抛出 JavaScript 错误?

发布于 2024-08-07 13:04:08 字数 851 浏览 2 评论 0原文

我在 ASP.NET 中编写了 COMET/Reverse Ajax 表控件。 javascript 部分使用 jQuery (1.3.2)。除了在 IE (8) 中关闭浏览器时之外,它似乎工作正常。只有当IE关闭时我才会收到错误。 Firefox 和 Chrome 不会抛出错误。在这种情况下,它会抛出一个

Microsoft JScript 运行时错误:对象不支持此属性或方法

该控件是 System.Web.UI.WebControls.Table 的后代。

有问题的行是:

var currentCell = $("#" + gridName + " tr:nth-child(" + (rowIndex + 1) + ") td:nth-child(" + (cellIndex - rowIndex * columnCount + 1) + ")");

gridName 是作为参数传递到函数中的控件的 ID。包含此行的函数被调用以响应成功的 Ajax POST 请求。

当页面打开时,控件按预期工作。

我假设问题是由于浏览器关闭时删除了某些内容,因此未完成的 Ajax 请求在返回时会失败。然而这只是一个猜测——我对 jQuery 不太熟悉。我尝试在 window.unload 事件中设置一个标志,以防止在发生 unload 事件后调用有问题的代码,但这并没有解决问题。

除了 jQuery 之外,我没有使用任何 Javascript 库。 javascript 作为 WebResource 包含在内。

当我导航到新页面时,仅当浏览器关闭时,才不会出现此问题。

I've written a COMET/Reverse Ajax table control in ASP.NET. The javascript part uses jQuery (1.3.2). It seems to be working OK, apart from when closing the browser in IE (8). It's only when IE is closed that I get the error. Firefox and Chrome don't throw an error. In this case it throws a

Microsoft JScript runtime error: Object doesn't support this property or method

The control is a descendent of System.Web.UI.WebControls.Table.

The offending line is:

var currentCell = $("#" + gridName + " tr:nth-child(" + (rowIndex + 1) + ") td:nth-child(" + (cellIndex - rowIndex * columnCount + 1) + ")");

gridName is the ID of the control which is passed into the function as a parameter. The function containing this line is called in response to a successful Ajax POST request.

The control works as expected while the page is open.

I'm assuming the problem is the result of something being removed when the browser closes, so the outstanding Ajax request fails when it returns. However this is just a guess - I'm not that familiar with jQuery. I tried setting a flag in the window.unload event to prevent the offending code being called after the unload event occurs, but this didn't solve the problem.

I'm not using any Javascript libraries other than jQuery. The javascript is include as a WebResource.

The problem does not occur when I navigate to a new page - only when the browser is closed.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文