Skip to content

Instantly share code, notes, and snippets.

@erichelgeson
Created March 20, 2019 02:21
Show Gist options
  • Save erichelgeson/ba3c30eec4c92836704c3bb48f346aa7 to your computer and use it in GitHub Desktop.
Save erichelgeson/ba3c30eec4c92836704c3bb48f346aa7 to your computer and use it in GitHub Desktop.
Using `fetch()` with ajaxAuth in Grails
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