jQuery Live在无限循环中提交Caugth [英] jQuery live submit caugth in infinite loop

查看:173
本文介绍了jQuery Live在无限循环中提交Caugth的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用jQuery提交表单,在我不得不添加确认窗口之前,它工作得很好,以便用户可以在提交之前查看其数据,这是代码:

I'm trying to submit a form using jQuery and it worked just fine until I had to add a confirmation window so users can review their data before submission, here's the code:

$("#create-group-form").live('submit', function(e){
    e.preventDefault();
    var form = $(this);
    jConfirm('Here I display the group info...', 'Confirm Group', function(r){
        if ( r ) {
            form.submit();
        }
    });
});

我正在使用jQuery的jAlert插件,但是它就像具有不同样式的常规Confirm提示一样工作,问题是当用户在提示上单击Ok时,它将再次进入实时提交并陷入无限循环.

I'm using the jAlert plugin for jQuery but it works just as a regular Confirm prompt with different styling, the preblem is that when users click Ok on the prompt it goes again into the live submit getting stuck in an infinite loop.

在确认后,是否有办法阻止它再次进入该事件?我想我可以通过某种方式取消绑定,但是我还没有找到成功完成绑定的方法.

Is there a way to stop it from going in again this event after I confirm? I think I can unbind it somehow but I haven't found a way to do it successfully.

顺便说一句,由于表单位于模式窗口中,因此我正在使用实时提交.

BTW I'm using live submit because the form is in a modal window.

提前谢谢!

推荐答案

调用表单元素的submit方法,而不是jQuery选择的方法.这意味着不会触发jQuery处理程序:

Call the form element's submit method, rather than the jQuery selection's one. This means the jQuery handler won't be triggered:

$("#create-group-form").live('submit', function(e){
    e.preventDefault();
    var form = this; // <-- this line changed
    jConfirm('Here I display the group info...', 'Confirm Group', function(r){
        if ( r ) {
            form.submit();
        }
    });
});

这篇关于jQuery Live在无限循环中提交Caugth的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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