jQuery: Stop submitting form, perform script, continue submitting form?

前端 未结 8 1048
遇见更好的自我
遇见更好的自我 2021-02-04 02:09

I have a form, and when I submit him I execute multiple script. Here is my code:

$(\"#RequestCreateForm\").submit(function (e) {
    if ($(\"#RequestCreateForm\"         


        
相关标签:
8条回答
  • 2021-02-04 03:00

    return; is the same thing as e.preventDefault();

    try

    $("#RequestCreateForm").trigger('submit');
    
    0 讨论(0)
  • 2021-02-04 03:01

    To avoid submit loops, an additional variable should be used.

    var codeExecuted = false;
    $('#RequestCreateForm').submit(function(e) {
        ...
        if(!codeExecuted){
            e.preventDefault();
            ...
            functionExecuted = true;
            $(this).trigger('submit');
        }
    });
    
    0 讨论(0)
提交回复
热议问题