【问题标题】:where should i put the code of sweetalert to confirm delete?我应该把sweetalert的代码放在哪里确认删除?
【发布时间】:2019-03-12 10:52:23
【问题描述】:

这是我在
index.blade.php

上的代码
{{ Form :: open  (['method'=>'DELETE', 'route'=>['assistants.destroy', $value -> id , 'style'=> 'Display']])}}

                <button  type="submit" style="display: inline;" class="btn btn-danger btn-sm" ><i class=" glyphicon glyphicon-trash">

                    </i>
                </button>
                {{ Form::close() }}

【问题讨论】:

  • Swal.fire({ title: 'Are you sure?', text: "You will not able to revert this!", type: 'warning', showCancelButton: true, confirmButtonColor: ' #3085d6', cancelButtonColor: '#d33', confirmButtonText: '是的,删除它!' }).then((result) => { if (result.value) { Swal.fire('Deleted!', '你的文件已删除。', 'success' ) } }) 这是 sweetalert 的代码

标签: laravel sweetalert2


【解决方案1】:

假设您在项目中使用 laravel 5.5+,那么您可以执行以下操作:

在您的表单中添加一个 ID:

{!! Form::open(['method'=>'DELETE', 'route'=>['assistants.destroy', $value -> id , 'style'=> 'Display', 'id' => 'MyDeleteForm']]) !!}
<button  type="submit" style="display: inline;" class="btn btn-danger btn-sm">
    <i class=" glyphicon glyphicon-trash"></i>
</button>
{!! Form::close() !!}

然后您可以使用此脚本使用 ajax 左右来处理您的请求:

var MyDeleteForm = $('#MyDeleteForm');
MyDeleteForm.submit(function(e) {
    e.preventDefault();
    Swal.fire({ 
        title: 'Are you sure?', 
        text: "You won't be able to revert this!", 
        type: 'warning', 
        showCancelButton: true, 
        confirmButtonColor: '#3085d6', 
        cancelButtonColor: '#d33', 
        confirmButtonText: 'Yes, delete it!' 
    }).then((result) => { 
        $.ajax({
            url: url,
            type: 'POST',
            data: formData,
            success: function(data) {
                Swal.fire( 'Deleted!', 'Your file has been deleted.', 'success' ) 
            },
            error: function(error) {
                console.log(error);
            }
        });
    });
});

我希望这会对你有所帮助。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-02-27
    • 1970-01-01
    • 1970-01-01
    • 2014-02-25
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多