[英]jQuery submit method doesnt submit form data
I am using jQuery to prevent submitting form on clicking if amount is <10 and using jQuery AJAX to update amount after every 2 seconds. 我使用jQuery来防止提交金额小于10的点击表单,并使用jQuery AJAX每2秒更新一次金额。 If meanwhile amount > 10 then I want to re-submit the form which is already filled.
如果同时金额> 10,那么我想重新提交已经填写的表格。
I have used 我用过
$("form").submit(function(e){ e.Preventdefault;})
To prevent submitting the form when amount < 10 and if meanwhile amount updates to > 10 then I am unbinding the submit button and calling submit function again. 为了防止在金额<10时提交表单,并且同时金额更新为> 10,则我将解除绑定提交按钮并再次调用Submit函数。
$("form").unbind("submit");
$("form").submit();
But this doesnt POST the data to action URL. 但是,这并不发布数据到操作URL。
Here's my complete code 这是我完整的代码
$(document).ready(function() {
var damount;
var checking=0;
setInterval(Call2, 3000);
function Call2() {
damount=$("#damount").val();
if(damount>10 && checking==1)
{
$("form").unbind('submit');
$("form").submit();
}
}
$("#addproject").click(function(){
checking=1;
damount=$("#damount").val();
if(damount<10)
{
$("form").submit(function(e){
e.preventDefault();
});
}
});
See another similar post and my response here: 在这里看到另一个类似的帖子和我的回复:
https://stackoverflow.com/a/25806502/4021932 https://stackoverflow.com/a/25806502/4021932
You're trying to call submit() on a jQuery object, which won't work. 您正在尝试在jQuery对象上调用Submit(),该方法无法正常工作。 You need to call it on the DOM element.
您需要在DOM元素上调用它。
$("form").unbind('submit'); //This is fine as it's dealing with the submit event, which jQuery handles
$("form")[0].submit(); //This calls submit() on the form DOM element
What about trying something like this: 尝试这样的事情呢:
$(function () {
$("form").submit(function (e) {
var damount = parseInt($("#damount").val());
if (damount < 10) {
e.preventDefault();
}
});
setInterval(function () {
$("form")[0].submit();
}, 3000);
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.