live()中的jQuery ajax提交仅在Firefox中不起作用 [英] jQuery ajax submission inside live() not working in Firefox only

查看:81
本文介绍了live()中的jQuery ajax提交仅在Firefox中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下代码,这些代码提交了一个表单并将其替换为服务器的响应:

I have the following code that submits a form and replaces itself with the server's response:

  $("form.replaceWithResponse").live("submit", function() {
    event.preventDefault(); // not preventing default form submission in Firefox
    var $this = $(this);
    $.ajax({
      data: $this.serialize(),
      dataType: "html",
      type: $this.attr("method"),
      url: $this.attr("action"),
      success: function(html) {
        $this.replaceWith(html);
      }
    });
  });

它在Chrome中可用,但在Firefox中不起作用,除非我在末尾使用return false而不是在开头使用event.preventDefault().为什么?

It works in Chrome, but it doesn't work in Firefox unless I use return false at the end rather than event.preventDefault() at the beginning. Why?

谢谢!

推荐答案

您需要传递事件:

$("form.replaceWithResponse").live("submit", function(event) {
    event.preventDefault();

这篇关于live()中的jQuery ajax提交仅在Firefox中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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