Form not submitting inside $.ajax success function

前端 未结 11 1646
被撕碎了的回忆
被撕碎了的回忆 2021-01-18 20:34

I\'m validating for duplicate names by using jquery+Ajax. Everything is working fine except that the form is not submitting once everything returns true

What

11条回答
  •  终归单人心
    2021-01-18 21:29

    Dont try to much check get simple button and affffd onclick event in that event put the code below

    html code

    
    

    javascript code

        function formsubmit() {
         var name = $('#shelf_name').val();
    
         if (name == '') {
             alert('Shelf name is required');
             $('#shelf_name').focus();
         } else {
             $.ajax({
                 type: 'post',
                 url: 'check-duplicate-shelf-name.php',
                 data: {
                     'name': name
                 },
                 context: this,
                 success: function (data) {
                     if (data == 'stop') {
                         alert('Shelf name already exists'); // working if duplicate name is found
                     } else {
                         alert('else working?'); // alert box is showing up if name is not duplicate
                         $('#form1').submit()
                     }
                 }
             });
         }
     }
    

提交回复
热议问题