JSFiddle - React, Tailwind, and code Playground
by Nicolas PUJOL
JavaScript
function apiCall(action, options, headers, verb) {
if (typeof headers !== "object") headers = {};
if (typeof options !== "object") options = {};
$.ajax({
type: verb,
dataType: 'json',
url: action,
data: options,
headers: headers,
success: function (data) {
console.log(data, "success");
},
error: function (data) {
return {data: data, type: "error"};
}
});
}
console.log(apiCall("/echo/json/", {"json": JSON.stringify({"text1": "textData1", "text2": "textData2"})}, {"X-Session-Token": "TOKEN"}, "POST"));