Created
February 15, 2017 18:01
-
-
Save bolak/857ed65860c38b7b0d40e20ee9b1747c to your computer and use it in GitHub Desktop.
Registration POST request example.
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
| $('.sign-up-form__registration-form').submit(function(e) { | |
| $("#password-error").remove(); | |
| var form = this; | |
| var formData = { | |
| firstName: $('input[name=first]', form).val(), | |
| lastName: $('input[name=last]', form).val(), | |
| email: $('input[name=email]', form).val(), | |
| dob: $('select[name=dob]', form).val(), | |
| password: $('input[name=password]', form).val(), | |
| passwordConfirmation: $('input[name="password-confirmation"]', form).val(), | |
| zip: $('input[name=zip]', form).val() | |
| }; | |
| var requestData = { | |
| "user": { | |
| "password": formData.password, | |
| "role": "participant", | |
| "email": formData.email | |
| }, | |
| "answers": [ | |
| { | |
| "questionId": 1, | |
| "answer": { | |
| "textValue": formData.firstName | |
| } | |
| }, | |
| { | |
| "questionId": 2, | |
| "answer": { | |
| "textValue": formData.lastName | |
| } | |
| }, | |
| { | |
| "questionId":3, | |
| "answer": { | |
| "textValue": formData.zip | |
| } | |
| }, | |
| { | |
| "questionId": 4, | |
| "answer": { | |
| "yearValue": formData.dob | |
| } | |
| } | |
| ], | |
| "signatures": [1], | |
| "language": "en" | |
| }; | |
| e.preventDefault(); | |
| if (formData.password === formData.passwordConfirmation) { | |
| $.ajax({ | |
| type: "POST", | |
| contentType: "application/json", | |
| url: "https://app-5154.on-aptible.com/api/v1.0/profiles", // Staging Development API. | |
| data: JSON.stringify(requestData) // please make sure to handle errors ( I've taken out our handlers since I figured you would like to write your own.) | |
| }); | |
| } else { | |
| $('.sign-up-form').append("<p id='password-error'>Your passwords must match.</p>"); | |
| } | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment