Yii2 ajax 提交

jQuery(document).on('beforeSubmit', function (event) {
    var $form = jQuery(event.target),
        data = $form.data('yiiActiveForm');

    var $button = data.submitObject,
        extData = '&' + data.settings.ajaxParam + '=' + $form.attr('id');
    if ($button && $button.length && $button.attr('name')) {
        extData += '&' + $button.attr('name') + '=' + $button.attr('value');
    }

    jQuery.ajax({
        url: $form.attr('action'),
        type: $form.attr('method'),
        data: $form.serialize() + extData,
        dataType: data.settings.ajaxDataType,
    });
    return false;
});

你可能感兴趣的:(Yii2 ajax 提交)