Skip to content

Instantly share code, notes, and snippets.

@joshuaquek
Last active November 9, 2022 17:55
Show Gist options
  • Save joshuaquek/c259497db73d596517522c1820f480a6 to your computer and use it in GitHub Desktop.
Save joshuaquek/c259497db73d596517522c1820f480a6 to your computer and use it in GitHub Desktop.
Summary: Some code for making AJAX requests from a NodeJs server or from the browser (React/Vue/Angular) via the Axios node npm module.
axios({
method: 'post',
url: 'http://google.com',
headers: {
'Content-Type': ' application/json'
},
data: {
'username': 'theUsernameHere1234',
'password': 'thePasswordHere1234',
}
}).then((response) => {
console.log(response)
}).catch(error => console.log(error.response.data))
// Assuming that this is within an async function...
try{
let response = await axios({
method: 'post',
url: 'http://google.com',
headers: {
'Content-Type': ' application/json'
},
data: {
'username': 'theUsernameHere1234',
'password': 'thePasswordHere1234',
}
})
} catch(error){
console.log(error.response.data)
}
@simplecheatsheet
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment