Send data with PUT-Request
You need to send the data as x-www-form-urlencoded
xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
And you have to call the defined function inside the .click()
$(#submit).click(){
var xmlHttp = getNewHTTPObject(); //returns a XMLHttpRequest object
chargeURLPut('url');
function chargeURLPut(url) {
var mimeType = "text/plain";
xmlHttp.open('PUT', url, true); // true : asynchrone false: synchrone
xmlHttp.setRequestHeader('Content-Type', mimeType);
xmlHttp.send($('#data').val());
}
});
You could try using the $.ajax call.
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$('#submit').click( function () {
console.log("click");
var sendData = $('#data').val();
$.ajax({
url: 'localhost', //Your api url
type: 'PUT', //type is any HTTP method
data: {
data: sendData
}, //Data as js object
success: function () {
}
})
;
});
});
</script>
</head>
<body>
<form>
Data:<br>
<input id="data" type="text" name="data" value="Mickey"><br>
<input id="submit" type="button" value="Submit">
</form>
</body>
</html>
I tested this on a webserver. It works.