0

我正在使用 Sweetalert2 来确认和更新一些数据。sweetalert 的风格与 bootstrap v4 (alpha) 相结合。多表单输入是用 HTML 生成的,就像这个例子一样。获取输入数据后,将进行 ajax 调用以对其进行更新。下面是我的例子:

swal({
    title: 'Submit to confirm',
    html:
        '<input id="swal-input1" placeholder="input1" class="form-control mb-1">' +
        '<input id="swal-input2" placeholder="input2" class="form-control">',
    showCancelButton: true,
    confirmButtonText: 'Submit',
    showLoaderOnConfirm: true,
    buttonsStyling: false,
    confirmButtonClass: 'btn btn-primary btn-lg',
    cancelButtonClass: 'btn btn-lg',
    preConfirm: function () {
        return new Promise(function (resolve) {
            resolve([
                $('#swal-input1').val(),
                $('#swal-input2').val()
            ])
       })
    },
    allowOutsideClick: false
    }).then(function(email) {
        $.ajax({
            // ajax for post / get here to update current data with data from the input
        });
}).catch(swal.noop)
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link href="https://cdn.jsdelivr.net/sweetalert2/6.4.1/sweetalert2.css" rel="stylesheet"/>
<script src="https://cdn.jsdelivr.net/sweetalert2/6.4.1/sweetalert2.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.0.0-alpha.6/css/bootstrap.min.css" />

如何使用自定义数据应用验证(空表单)然后进行 ajax 调用?

4

0 回答 0