I have the following jQuery Ajax code:
$("#new_form").submit(function (event) {
event.preventDefault();
$.post("/home/new_ajax", $(this).serialize(), function (data) {
if (data.errors == '') {
$("#new_form").submit();
} else {
alert(data.errors);
}
}, "json");
});
However, due to
event.preventDefault();
this line doesn’t work:
$("#new_form").submit();
Is there any way to get around this?
You can use
.trigger()instead of.submit()— it allows you to pass in extra parameters which your event handler can then utilize: