PUT vs POST
HTML
<a href="#" data-request="PUT">Test PUT</a> | <a href="#" data-request="POST">Test POST</a>
<h1>Response</h1>
<div id="response"></div>
CSS
body {
font-family: Helvetica, Sans, Arial;
}
p, ul {
padding: 10px;
}
#response {
font-family: "Lucida Console", Monaco, monospace
}
JavaScript
$('a').click(function() {
$.ajax({
"url": 'http://example.com/1.php',
"type": $(this).data('request'),
"success": function(data, textStatus, xhr) {
$('#response').append(xhr.responseText + '<br>');
},
"error": function(xhr, textStatus, error) {
$('#response').append(error + '<br>');
},
"timeout": 10000,
"headers": {
"Content-Type": 'application/json; charset=UTF-8',
"Cookie": 'PHPSESSID=r4poidb73aulee4091b4va4kd0',
},
"crossDomain": true,
"xhrFields": { withCredentials: true },
"data": 'TEST'
});
});