我收到以下错误与下面的JavaScript代码:不留神编码无限循环进入我的ASP.NET MVC应用程序的jQuery代码
RangeError: Maximum call stack size exceeded
我假设,这意味着我不小心编码一个无限循环到我的JavaScript。此代码来自使用jQuery Validate的ASP.NET MVC应用程序。此代码的目的是在提交之前检查页面上捕获的图像。
本质上,这是另一个需要与jQuery Validate一起发生的前端验证。似乎我唯一的选择是在提交表单时运行此代码,特别是因为在“提交”按钮单击和提交之间没有其他事件发生。这里是代码:
$('form').submit(function (e) {
e.preventDefault();
//If Corporation is selected as business type
if ($('#businessStructure').val() == "Corporation") {
//Checks CEO signature present
if ($("#signImage").length == 0 || $("#signImage").attr("src") == "") {
alert("Please sign and save your signature in the CEO signature pad");
$("#ceoError").show();
}
else {
//all good, an image exists
$('form').submit();
}
}
//If Sole Proprietor is selected as business type
else if ($('#businessStructure').val() == "SoleProprietor") {
//Checks CEO signature present
if ($("#signImage").length == 0 || $("#signImage").attr("src") == "") {
alert("Please sign and save your signature in the CEO signature pad");
$("#ceoError").show();
}
//Checks partner1 signature present
if ($("#signImage1").length == 0 || $("#signImage1").attr("src") == "") {
alert("Please sign and save your signature in the first partner signature pad");
$("#partner1Error").show();
}
else {
//all good, an image exists
$('form').submit();
}
}
else {
//Checks CEO signature present
if ($("#signImage").length == 0 || $("#signImage").attr("src") == "") {
alert("Please sign and save your signature in the CEO signature pad");
$("#ceoError").show();
}
//Checks partner1 signature present
if ($("#signImage1").length == 0 || $("#signImage1").attr("src") == "") {
alert("Please sign and save your signature in the first partner signature pad");
$("#partner1Error").show();
}
//Checks partner2 signature present
if ($("#signImage2").length == 0 || $("#signImage2").attr("src") == "") {
alert("Please sign and save your signature in the second partner signature pad");
$("#partner2Error").show();
}
else {
//all good, an image exists
$('form').submit();
}
}
});
这是我第一次做了MVC应用程序表单提交的并发事件。有没有我不知道的另一种方法?
这是因为您调用'$('form')。submit();'。如果你想让它做正常的表单提交,不要调用'e.preventDefault()'。 –
您一次又一次地调用函数'$(form).submit()'。它是递归的。这可能会有所帮助:https://stackoverflow.com/questions/7065120/calling-a-javascript-function-recursively – colecmc
我试图从$('form')改变事件。submit(function(e)to $(' #submitButton')。click(function(e),但它工作不正常。警告框出现,但表单仍在提交。任何想法? – cryan