Created
June 14, 2016 11:39
-
-
Save chodorowicz/e94a63db1e360cb92ec05cf15078fa64 to your computer and use it in GitHub Desktop.
jQuery serialize form using serializeArray
This file contains 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
function serializeForm($form) { | |
return $form.serializeArray().reduce( (result, input) => { | |
result[input.name] = input.value; | |
return result; | |
}, {} | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Sure. But if multiple inputs have the same name, this will only return the first one of them. Which maybe fine in your case. If you need a more complete solution, check out https://github.com/marioizquierdo/jquery.serializeJSON