Infinite loop of form submit using jquery event

[亡魂溺海] 提交于 2019-11-29 03:42:09

I assume your ajax is an attempt to validate the form before its eventual submission. In that case just unbind the validation function before submitting the form.

  success: function(response){
     $('input[name="field1"]').val(response);
     // Add unbind to remove validations
     $('form').unbind().submit(); 
  }

In the success you trigger another submit...

$('form').submit(function(e){
   e.preventDefault(); // redundant,  you return false in the end. <<<===
   $.ajax({
      type: "POST",
      url: 'convert.asp',
      data: $('form').serialize(),
      success: function(response){
         $('input[name="field1"]').val(response);
         $('form').submit(); // <=== delete this! <<<<=================
      }
   });
   return false;
});

You submit your form, prevent submission only to submit the form, which gets prevented to get submitted... :-D

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!