猿问

如何防止Ajax表单提交写在任何地方?

我正在基于WordPress中的另一个专业插件开发一个插件。我想停止用另一个插件编写的Ajax表单提交。我无法在其他插件中更改Ajax代码。


当前场景


当我提交表单时,它将带我到新页面,但同时它还会运行ajax请求。我想停止该ajax请求。简而言之,我只想用新页面正常提交我的表格。


的HTML


<form id="redirect_form" class="abc-form" method="post" name="New Form" action="http://example.com/form-redirect">

    <label for="form-field-field_1" class="abc-field-label">Test</label>

    <input type="text" name="form_fields[field_1]" id="form-field-field_1" placeholder="Enter a location" autocomplete="off">            

    <button type="submit" class="form_redirect_to">Submit</button>

</form>

jQuery的


jQuery(document).ready(function($){

  jQuery('#redirect_form').on('submit',function(e){

    e.preventDefault();

    e.stopPropagation();

    $(this).off("submit");

    this.submit();

    return false;

  });

});


慕的地8271018
浏览 107回答 1
1回答

人到中年有点甜

正如您通过注释提到的那样,默认的Jquery事件是使用表单的类绑定的。通过更改默认类,该事件将不再在默认Jquery函数中触发。改变:<form&nbsp;id="redirect_form"&nbsp;class="abc-form">经过:<form&nbsp;id="redirect_form"&nbsp;class="another-class">
随时随地看视频慕课网APP

相关分类

JavaScript
我要回答