JSFiddle - React, Tailwind, and code Playground
HTML
<button id="button">Send an HTTP POST request to a page and get the result back</button>
<div id="div">
JavaScript
$(document).ready(function() {
$("#button").click(function() {
makePostRequest("http://www.mocky.io/v2/587ccd320f000081015dxxxx", "dummy_json", null, "post", "json", "div");
});
});
function makePostRequest(url, data, headers, httpVerb, dataType, elementId) {
$.ajax({
url: url,
type: httpVerb,
data: data,
headers: {
Header_Name_One: 'Header Value One',
"Header_Name_Two": 'Header Value Two'
},
dataType: 'json',
success: function(data) {
alert("success");
}
}).done(function(msg) {
alert('done');
});
}