Jquery表单提交保持刷新

由于某种原因,这个表单不断刷新页面,我不知道为什么因为我在页面上有另一个表单,具有不同的id但相同的脚本,并且它不刷新。 我尝试过使用preventDefault(); 同样,但它也不起作用。 有人可以告诉我这个表格或脚本出错了吗?

谢谢

页面顶部

   

表格

 

<input type="hidden" id="code" size="12" readonly="true" value="" />

脚本 – 从member_info.js链接

 $(document).ready(function(){ $("form#central").submit(function() { var code = $('#code').val(); var inception = $('#creddate').val(); var surety = $('#surety').val(); var credit = $('#creditlimit').val(); $.ajax ({ type: "POST", url: '../members/edit_central.php', data: {code: code, creddate: creddate, surety: surety, creditlimit: creditlimit}, success: function(data) { $('#central_status').html(data); } }); return false; }); }); 

确保在提交表单后立即使用preventDefault() 。 在你这样做之前不要做任何其他事情(比如调用Ajax)。

例如:

 $("form#central").submit(function(e) { e.preventDefault(); // Your other long running (possibly async) // operations here } 

此外,请确保您没有动态地将表单添加到页面。 如果您这样做,则需要实时附加提交事件。 像这样:

 $(document).on('submit', 'form#central', function(e){ // same as above }); 

使用提交的输入类型按钮

  

在click事件处理结束时简单返回false,例如:

 $('form input[type="submit"]').click(function() { .... return false; })