Sweetalert软件包和jQuery Submit()无法正常工作 [英] Sweetalert package and jQuery submit() not working correctly

查看:92
本文介绍了Sweetalert软件包和jQuery Submit()无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用sweetalert库.这是我的表格:

Using sweetalert library. Here's my form:

<form id="delete-currency" style="display:inline;" method="POST" action="/admin/currency/7">
   <input type="hidden" name="_token" value="sIgpTKlPJ4Z3Co4daRwGpZ8rz10TCM6Ynre8sdsdsd">
   <input type="hidden" name="_method" value="DELETE">
   <button type="button" class="btn btn-danger btn-delete"><i class="fa fa-trash-o" aria-hidden="true"></i></button>
</form>

7-是商品ID.

然后我正在使用确认窗口(sweetalert):

Then i am using confirm window (sweetalert):

<script type="text/javascript">
    $('.btn-delete').click(function() {
        swal({
            title: "Are you sure?",
            text: "blablabla!",
            type: "warning",
            showCancelButton: true,
            confirmButtonColor: "#DD6B55",
            confirmButtonText: "Yes, i am sure",
            closeOnConfirm: false,
            cancelButtonText: "Cancel"
        },
        function(isConfirm) {
            $('#delete-currency').submit();
        });
    });

</script>

我有一个资源控制器,该控制器接受具有货币ID的delete方法.但是,如果我将wealalert与jquery submit()一起使用,它将始终发送"1",而不是实际的$currency->id

I have a resource controller, which accepts delete method with currency id. However if i use sweetalert with jquery submit() it always sends "1" instead of actual $currency->id

我的控制器:

public function destroy($id)
{
    dd($id);
    $currency = Currency::findOrFail($id);
    $currency->delete();
    alert()->success('asdasdsadad', 'Success')->persistent('close');
    return redirect('/admin/currency');
}

dd($ id)始终显示"1".

dd($id) shows "1" all the time.

routes.php:

routes.php:

Route::group(['prefix' => 'admin', 'middleware' => ['auth', 'admin']], function() {
    Route::resource('currency', 'CurrencyController');
});

怎么了?

推荐答案

尝试一下.

 $('.btn-delete').on('click',function(e){
    e.preventDefault();
    var form = $(this).parents('form');
swal({
    title: "Are you sure?",
     text: "blablabla!",
     type: "warning",
    showCancelButton: true,
    confirmButtonColor: "#DD6B55",
    confirmButtonText: "Yes, delete it!",
    closeOnConfirm: false
}, function(isConfirm){
    if (isConfirm) form.submit();
});

})

我认为这将为您提供正确的价值.

I think this will give you the right value.

希望有帮助

这篇关于Sweetalert软件包和jQuery Submit()无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆