开发者

jQuery ajax submission inside live() not working in Firefox only

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: $th开发者_开发技巧is.attr("action"),
      success: function(html) {
        $this.replaceWith(html);
      }
    });
  });

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?

Thanks!


You need to pass in the event:

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜