卸载/删除或重用已加载的 JavaScript
我正在尝试将 jsp 文件加载到 jQuery UI 对话框 http://jqueryui.com/demos/dialog /。该 jsp 包含一个 fullCalendar http://arshaw.com/fullcalendar/ 日历。控制台调用 calLoader.jsp,它或多或少只包含:
<jsp:include page="../cal.jsp"/>
当我第一次打开对话框时,一切正常,但是在我关闭对话框并尝试再次打开它之后,我从 Chrome 中得到以下堆栈跟踪
Uncaught RangeError: Maximum call stack size exceeded
d.d.extend._Deferred.f.resolveWith
d.d.extend._Deferred.f.done
d.d.fn.d.ready
d.d.fn.d.init
d.d
(anonymous function)
d.d.extend.globalEval
ba
d.d.extend.each
d.fn.extend.domManip
d.fn.extend.append
d.fn.extend.html
d.fn.extend.load.d.ajax.complete
d.d.extend._Deferred.f.resolveWith
v
d.support.ajax.d.ajaxTransport.send.c
:问题在 Firefox 中是相同的,但我收到消息:
too much recursion
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
我意识到我正在尝试加载多个相同的内容,并且它以某种方式需要重用或卸载/删除并重新加载,但我不知道如何这样做。
这是我用来打开日历的代码(根据要求)。
function openCalendar() {
var dialog = jQuery('<div id="calendaropener"></div>')
.dialog({
autoOpen: false,
draggable: true,
modal: false,
resizable: false,
width: 820,
height: 750,
position: [50, 50],
title: 'Kalender',
close: function(ev, ui) { calendarObj = null; }
});
dialog.load("calLoader.jsp");
dialog.dialog('open');
}
函数 openCalendar() 是从我的页面上的按钮调用的。 谢谢!
I'm trying to load a jsp-file into a jQuery UI dialog http://jqueryui.com/demos/dialog/. The jsp contains a fullCalendar http://arshaw.com/fullcalendar/ calendar. The console calls for calLoader.jsp which more or less only contains:
<jsp:include page="../cal.jsp"/>
When I open the dialog the first time, everything works just fine, but after I close the dialog and try to open it again, I get the following stacktrace from Chrome:
Uncaught RangeError: Maximum call stack size exceeded
d.d.extend._Deferred.f.resolveWith
d.d.extend._Deferred.f.done
d.d.fn.d.ready
d.d.fn.d.init
d.d
(anonymous function)
d.d.extend.globalEval
ba
d.d.extend.each
d.fn.extend.domManip
d.fn.extend.append
d.fn.extend.html
d.fn.extend.load.d.ajax.complete
d.d.extend._Deferred.f.resolveWith
v
d.support.ajax.d.ajaxTransport.send.c
The problem is the same in firefox but I get the message:
too much recursion
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
I realize that I'm trying to load the same stuff more than one and that it somehow needs to be either reused or unloaded/removed and reloaded, but I have no clue how to do that.
This is the code I use to open the calendar (was requested).
function openCalendar() {
var dialog = jQuery('<div id="calendaropener"></div>')
.dialog({
autoOpen: false,
draggable: true,
modal: false,
resizable: false,
width: 820,
height: 750,
position: [50, 50],
title: 'Kalender',
close: function(ev, ui) { calendarObj = null; }
});
dialog.load("calLoader.jsp");
dialog.dialog('open');
}
The function openCalendar() is called from a button on my page.
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我的猜测是,关闭第一个元素后,它只是隐藏的,然后创建另一个具有相同 id 的元素,这会导致加载过程出现问题。理想情况下,为了对 DOM 进行更多控制,我首先将日历开启器 div 放在主页中,然后创建对话框,如下所示:
这可以帮助您更轻松地管理/调试它。
如果你不想这样做,那么你可以尝试添加到你的 close 函数中:
这将确保该元素从 DOM 中删除,这样你就不会因为多次添加该元素而出现任何奇怪的问题。
最后,如果您只想处理隐藏和重新打开(假设这不会破坏您的逻辑),那么您可以有条件地触发
dialog.load("calLoader.jsp");
,例如:希望那里有帮助!
My guess would be that after you close the first one it's only hidden and then you create another element with the same id, that causes a problem with the loading process. Ideally, to exercise a bit more control over the DOM I would start with having my calendar opener div in the main page, then creating the dialog as such:
This may help you to manage / debug it a little more easily.
If you don't want to do that then you might try adding to your close function:
This will ensure the element is removed from the DOM so you're not going to get any quirky issues that could follow from adding the element more than once.
Finally if you did just want to handle hiding and re-opening (assuming this doesn't break your logic) then you could trigger the
dialog.load("calLoader.jsp");
conditionally, e.g.:Hope something there helps!