【问题标题】:Re-binding an ajaxForm after content re-loads with ajax (jQuery 1.4.2)使用 ajax 重新加载内容后重新绑定 ajaxForm (jQuery 1.4.2)
【发布时间】:2010-05-11 22:07:05
【问题描述】:

我试图弄清楚为什么在使用 jQuery 1.4.2 而不是 1.3.2 时这是一个问题。

这是我的功能:

function prepare_logo_upload() {
    $("#logo-upload-form").ajaxForm({
        //alert(responseText);                                       
        success: function(responseText) {
            //alert(responseText);                                          
            $('#profile .wrapper').html(responseText);
            prepare_logo_upload();
        }
    });
}

其他所有实时事件都可以使用,但不能使用 .live() 方法,因为 ajaxForm 是一个插件。 对于使用旧表单(回调后重新绑定)的其他类型的绑定(点击),我也注意到了这一点

你能告诉我这是否是解决这个问题的方法吗?

这是一个类似的问题,但由于我在这里的新手声誉,不能在那里发表评论或提问,所以我会在这里问一个新问题。 -> jQuery: Bind ajaxForm to a form on a page loaded via .load()

谢谢!

编辑:“#profile .wrapper”包含表单,所以我的问题是在重新加载后将其与事件重新绑定。

【问题讨论】:

  • #profile 是否包含#logo-upload-form
  • 是的,很抱歉没有提及!它加载表单并替换它,所以我在重新加载后重新绑定它的问题。

标签: jquery ajax binding dynamic-rebinding


【解决方案1】:

只是猜测,但是,是这样的吗?


$("#logo-upload-form").live("submit", function () {
    return (function () {
        jQuery(this).ajaxForm({
            //alert(responseText);                                       
            success: function(responseText) {
                //alert(responseText);                                          
                $('#profile .wrapper').html(responseText);
                // recursion 
                return arguments.callee();
            }
        });
    }());
});

完全未经测试,顺便说一句。

【讨论】:

  • 这很有趣,它在那个 .wrapper div 中再次加载整个页面我认为仅在提交时附加 ajaxForm 不起作用,它需要在加载时附加。不过,感谢您的尝试!
猜你喜欢
  • 2017-03-15
  • 2021-04-29
  • 2013-08-31
  • 2022-01-22
  • 2014-06-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多