我正在使用直接Web Remoting (DWR) JavaScript库文件,只在Safari(桌面和iPad)中得到一个错误
它说
超过最大调用堆栈大小。
这个错误到底是什么意思,它是否完全停止处理?
Safari浏览器也有任何修复(实际上是在iPad Safari上,它说
JS:执行超时
我认为这是相同的调用堆栈问题)
我正在使用直接Web Remoting (DWR) JavaScript库文件,只在Safari(桌面和iPad)中得到一个错误
它说
超过最大调用堆栈大小。
这个错误到底是什么意思,它是否完全停止处理?
Safari浏览器也有任何修复(实际上是在iPad Safari上,它说
JS:执行超时
我认为这是相同的调用堆栈问题)
当前回答
在我的例子中,click事件在子元素上传播。所以,我不得不写以下内容:
e.stopPropagation ()
点击事件:
$(document).on("click", ".remove-discount-button", function (e) {
e.stopPropagation();
//some code
});
$(document).on("click", ".current-code", function () {
$('.remove-discount-button').trigger("click");
});
下面是html代码:
<div class="current-code">
<input type="submit" name="removediscountcouponcode" value="
title="Remove" class="remove-discount-button">
</div>
其他回答
我知道这个帖子很旧了,但我认为值得一提的是我发现这个问题的场景,所以它可以帮助其他人。
假设你有这样的嵌套元素:
<a href="#" id="profile-avatar-picker">
<span class="fa fa-camera fa-2x"></span>
<input id="avatar-file" name="avatar-file" type="file" style="display: none;" />
</a>
您不能在其父元素的事件内操作子元素事件,因为它会传播到自身,进行递归调用,直到抛出异常。
所以这段代码会失败:
$('#profile-avatar-picker').on('click', (e) => {
e.preventDefault();
$('#profilePictureFile').trigger("click");
});
你有两个选择来避免这种情况:
将子对象移动到父对象的外部。 将stopPropagation函数应用于子元素。
你可以在crome浏览器中找到你的递归函数,按ctrl+shift+j,然后source选项卡,它会给你代码编译流程,你可以在代码中使用断点。
在我的情况下,我得到这个错误的ajax调用和数据,我试图传递的变量没有定义,这是显示我这个错误,但不是描述变量没有定义。我加上定义了变量n的值。
这个问题可能是因为递归调用没有任何终止的基本条件。
就像在我的情况下,如果你看到下面的代码,我有相同的API调用方法和方法,我用来执行操作后的API调用。
const getData = async () => {
try {
const response = await getData(props.convID);
console.log("response", response);
} catch (err) {
console.log("****Error****", err);
}
};
基本上,解决方案就是删除这个递归调用。
dtTable.dataTable({
sDom: "<'row'<'col-sm-6'l><'col-sm-6'f>r>t<'row'<'col-sm-6'i><'col-sm-6'p>>",
"processing": true,
"serverSide": true,
"order": [[6, "desc"]],
"columnDefs": [
{className: "text-right", "targets": [2, 3, 4, 5]}
],
"ajax": {
"url": "/dt",
"data": function (d) {
d.loanRef = loanRef;
}
},
"fnRowCallback": function (nRow, aData, iDisplayIndex, iDisplayIndexFull) {
var editButton = '';
// The number of columns to display in the datatable
var cols = 8;
// Th row element's ID
var id = aData[(cols - 1)];
}
});
在上面的数据函数中,我使用了相同的名称d.loanRef = loanRef,但没有创建变量loanRef,因此递归地声明了自己。
解决方案:声明一个loanRef变量,或者更好的是,使用与d.loanRef不同的名称。