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();
精彩评论