我在表单
之外有一个输入<input id="BrId" name="BrId" type="text" value="1">
HTML表格 -
<form id="photoform" enctype="multipart/form-data" method="post" action="server-side-path">
<input type="file" id="Photos" name="photo"/>
<input type="hidden" name="VisitGuid" value="5" />
<input type="hidden" name="HiddenBrId" id="HiddenBrId" value="" />
<input type="submit" />
的JQuery -
$('#photoform').on('submit', function (e) {
e.preventDefault();
$('#HiddenBrId').val($('#BrId').val());
$('#photoform').submit();
});
当我点击提交按钮时,表单未提交,控制台显示Uncaught RangeError: Maximum call stack size exceeded
任何帮助?
答案 0 :(得分:2)
<form id="photoform" enctype="multipart/form-data" method="post" action="server-side-path">
<input type="file" id="Photos" name="photo"/>
<input type="hidden" name="VisitGuid" value="5" />
<input type="hidden" name="HiddenBrId" id="HiddenBrId" value="" />
<input type="submit" name="submit_btn" />
</form>
<script>
$('#photoform').on('submit', function (e) {
e.preventDefault();
$('#HiddenBrId').val($('#BrId').val());
// Change is here
$('#photoform')[0].submit();
});
</script>
注意:请避免使用 提交 和 重置 作为来自输入的name
和id
属性。
答案 1 :(得分:1)
$('#photoform').on('submit', function (e) {
e.preventDefault();
$('#HiddenBrId').val($('#BrId').val());
// Change is here
$('#photoform')[0].submit();
});
答案 2 :(得分:1)
<强>原因强>
$('#photoform').on('submit', function (e) { //S-1
. . .
$('#photoform').submit(); //This is the cause, it again calls "S-1"
});
请解释一下你真正想要达到的目标。