Не удается отправить форму с использованием jquery - PullRequest
0 голосов
/ 22 сентября 2019

У меня проблема с отправкой формы в sweetalert2 с использованием jquery.

Вот код, который у меня есть:

<?=form_open_multipart('controller_path','id="form_service"' , ''?>
<input type="button" name="update" id="submit-operate" value="Submit To Operated" class="btn btn-success" onclick="service.submitService()"/>
<?= form_close(); ?>

и это service.js:

submitService: function(){
        swal({
            title: 'Are you sure?',
            text: "You will submit this service to the next phase",
            type: 'warning',
            showCancelButton: true,
            confirmButtonColor: '#3085d6',
            cancelButtonColor: '#d33',
            confirmButtonText: 'Submit'
        }).then((result) => {
          if (result.value) {
                $("#form_service").submit()
            }
        });
    }

Подсластитель также работает, и когда я делаю console.log в if(result.value), он отображается на консоли, но форма не отправляется.Может кто-нибудь показать мне правильный путь?Спасибо.

1 Ответ

0 голосов
/ 22 сентября 2019

Попробуйте это:

submitService = function(){
     var form = $("#form_service");
            swal({
                title: 'Are you sure?',
                text: "You will submit this service to the next phase",
                type: 'warning',
                showCancelButton: true,
                confirmButtonColor: '#3085d6',
                cancelButtonColor: '#d33',
                confirmButtonText: 'Submit'
            }).then((result) => {
              if (result.value) {
                    form.submit(); //semicolon in the end
                }
            });
        }
...