简体   繁体   English

jQuery与Laravel表单确认不起作用

[英]Jquery Confirm with Laravel Form does not work

I have this Jquery code: 我有这个jQuery代码:

<script type="text/javascript">
    $('.blog-form').submit(function (e) {
        e.preventDefault();
        var blog_form = $(this);

        bootbox.confirm("Are you sure?", function (result) {
            if (result) {
                blog_form.submit();
            }
        });
    });
</script>

And in my Laravel Form: 在我的Laravel表格中:

{!! Form::open(['action' => ['Test\\TestController@destroy', $thread->id], 'method' => 'delete',  'class' => 'blog-form']) !!}
{!! Form::submit('Delete', ['class' => 'btn btn-danger']) !!}
{!! Form::close() !!}

If I'm pressing the submit button, the confirm-message will appear. 如果按提交按钮,则会显示确认消息。 If I'm pressing on 'cancle', the confirmation of course disappear. 如果我按“ cancle”,则确认当然消失了。 so.. If I'm pressing the 'Ok' button, then the confirm message will fade out but at the same time a knew confirmation-message pops out. 如果我按“确定”按钮,则确认消息将消失,但同时弹出一个已知的确认消息。 over and over again. 一遍又一遍地。 So I can't press Ok, without getting another confirm-message. 因此,如果没有其他确认消息,我将无法按OK。 I wasn't able to solve this problem yet. 我还不能解决这个问题。 Thanks for any help :) 谢谢你的帮助 :)

The problem is that you are calling the same submit() function, which you intercept in jQuery. 问题在于您正在调用同一个submit()函数,您在jQuery中对其进行了拦截。 One way to prevent this, is by using a flag. 防止这种情况的一种方法是使用标志。

<script type="text/javascript">
    var confirmed = false;
    $('.blog-form').submit(function (e) {
        if(confirmed){
            return;
        }
        e.preventDefault();
        var blog_form = $(this);

        bootbox.confirm("Are you sure?", function (result) {
            if (result) {
                confirmed = true;
                blog_form.submit();
            }
        });
    });
</script>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM