Skip to content

Instantly share code, notes, and snippets.

@DominikAngerer
Last active October 10, 2018 13:53
Show Gist options
  • Select an option

  • Save DominikAngerer/df53197f264860139e803f0c9e83ade4 to your computer and use it in GitHub Desktop.

Select an option

Save DominikAngerer/df53197f264860139e803f0c9e83ade4 to your computer and use it in GitHub Desktop.
// You can send a POST request to the Node Application from your client side application
// during your submit event with the following three examples
// ----------------------------------------------------------------
// Basic XHR Example:
// in your submit event:
var data = JSON.stringify({ "message": "this is the message from the contact form entered by your customer" } );
var xhr = new XMLHttpRequest();
xhr.addEventListener("readystatechange", function () {
if (this.readyState === 4) {
console.log(this.responseText);
}
});
xhr.open("POST", "http://127.0.0.1:3020");
xhr.setRequestHeader("Content-Type", "application/json");
xhr.send(data);
// ----------------------------------------------------------------
// If you have jQuery
// in your submit event:
var data = { "message": "this is the message from the contact form entered by your customer" }
var settings = {
"async": true,
"crossDomain": true,
"url": "http://127.0.0.1:3020",
"method": "POST",
"headers": {
"Content-Type": "application/json",
"cache-control": "no-cache"
},
"processData": false,
"data": JSON.stringify(data)
}
$.ajax(settings).done(function (response) {
console.log(response);
});
// ----------------------------------------------------------------
// Axios example:
// in the top of your component
var axios = require('axios')
// in your submit event:
var data = { "message": "this is the message from the contact form entered by your customer" }
axios.post('http://127.0.0.1:3020', data)
.then(function (response) {
console.log(response);
})
.catch(function (error) {
console.log(error);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment