jQuery validator plugin + ajax submitting not working

前端 未结 3 528
梦如初夏
梦如初夏 2020-11-30 07:08

I use the jQuery validator plugin (1.11) from bassistance.de and submit via php. Now i have add an ajax call in the submit handler at the end of the javacript code, but the

3条回答
  •  难免孤独
    2020-11-30 07:31

    You have to put your code into the document ready callback, to be sure that the DOM(your form) is loaded before.

    $(document).ready(function() {
     //Code
    });
    

    You have to remove your existing .submit() from the submitHandler and place it outside the validation initialization but inside ready. Then inside the submitHandler you only call form.submit(); With form.submit(); you trigger submit, the other one is then fired.

    Or you place your $.ajax directly into submitHandler.

    The way you do it now, you only add the event listener at the time you click your submit button. Thats actually to late. Directly after that your form gets submitted without ajax.

提交回复
热议问题