I have a small function with jQuery Core 2.1.4:
function ajax(url, method, data, success) {
$.ajax({
contentType: "application/json",
data: JSON.stringify(data),
dataType: "json",
method: method,
processData: false,
url: url
});
}
And then this code:
var myPage = "http://localhost/blankResponse";
var myFunc = function(data) {
alert(data);
};
ajax(myPage, "POST", {}, myFunc); // Request to "testpage" with body
ajax(myPage, "PUT", {}, myFunc); // Request to "testpage" with body
ajax(myPage, "DELETE", {}, myFunc); // Request to "testpage" with body
ajax(myPage, "GET", {}, myFunc); // Request to "testpage?{}" with no body
GETing adds the data
parameter to the URL, whereas the other functions add it as the request body. Is there a way I can get (no pun intended!) jQuery to send the data in the request body?