I try to make a simple request to an api and get back the result, but my request is never launched (I am also looking in fiddler). What am I doing wrong?
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script>
$(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){
alert('click');
$.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');
});
}
</script>
</head>
<body>
<button id="button">Send an HTTP POST request to a page and get the result back</button>
<div id="div">
</body>
</html>