Created
July 5, 2013 09:13
-
-
Save benfoster/5933185 to your computer and use it in GitHub Desktop.
Handling modelstate errors when hijaxing a form
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $(".hijax").submit(function (e) { | |
| var $form = $(this), | |
| validator = $form.data("validator"); | |
| if (!$form.valid()) { | |
| return; | |
| }; | |
| $.ajax({ | |
| url: this.action, | |
| type: "POST", | |
| data: $form.serialize(), | |
| statusCode: { | |
| 400: function (xhr, textStatus, errorThrown) { | |
| var errors = $.parseJSON(xhr.responseText); | |
| validator.showErrors(errors); | |
| } | |
| }, | |
| error: function () { | |
| // reset submit button | |
| $("button[type=submit]").button("reset"); | |
| } | |
| }); | |
| e.preventDefault(); | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment