K
K
Kirill Kazakov2016-06-08 18:10:24
JavaScript
Kirill Kazakov, 2016-06-08 18:10:24

PJAX reloads (re-renders) the submit form itself, how to avoid this?

Based on this nix-tips.ru/yii2-primeryaem-pjax-na-activeform-ig... tutorial, I am submitting a form.
Everything is great, but the form is reloading, can this be avoided?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
K
Kirill Kazakov, 2016-06-09
@mausspb

Well written here for this occasion

$('body').on('beforeSubmit', ‘form#formId', function () {
     var form = $(this);
     // return false if form still have some validation errors
     if (form.find('.has-error').length) {
          return false;
     }
     // submit form
     $.ajax({
          url: form.attr('action'),
          type: 'post',
          data: form.serialize(),
          success: function (response) {
               // do something with response
          }
     });
     return false;
});

N
Nikita, 2016-06-08
@bitver

PJAX - pushState + Ajax. A priori, the next page should load.
Just use Ajax forms

G
Greg Popov, 2016-06-08
@Gregpopov

<?php Pjax::begin(['enablePushState'=>false]); ?>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question