Created
March 20, 2019 02:21
-
-
Save erichelgeson/ba3c30eec4c92836704c3bb48f346aa7 to your computer and use it in GitHub Desktop.
Using `fetch()` with ajaxAuth in Grails
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
const formData = new FormData() | |
formData.append('username', 'foo@bar.com'); | |
formData.append('password', 'password'); | |
const data = new URLSearchParams(formData); | |
fetch('/login/authenticate', { | |
method: "POST", | |
headers: { | |
"X-Requested-With": "XMLHttpRequest", | |
"Content-Type": "application/x-www-form-urlencoded", | |
}, | |
body: data | |
}).then(response => { | |
response.json().then(data => { | |
if(data.username) { | |
console.log(data.username) | |
} else { | |
console.log(data.error) | |
} | |
}) | |
}).catch(response => response.json().then(data => { | |
console.log(data) | |
})); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment