| 1 |
function wpda_rest_api(path, data, callbackOk, callbackError, method = "POST") { |
| 2 |
jQuery.ajax({ |
| 3 |
url: wpApiSettings.root + wpdaApiSettings.path + "/" + path, |
| 4 |
method: method, |
| 5 |
beforeSend: function (xhr) { |
| 6 |
xhr.setRequestHeader("X-WP-Nonce", wpApiSettings.nonce); |
| 7 |
}, |
| 8 |
data: data |
| 9 |
}).done(function(response) { |
| 10 |
if (callbackOk!==undefined) { |
| 11 |
callbackOk(response) |
| 12 |
} else { |
| 13 |
console.error("Missing API callback. Server response:") |
| 14 |
console.error(response) |
| 15 |
} |
| 16 |
}).fail(function(response) { |
| 17 |
if (callbackError!==undefined) { |
| 18 |
callbackError(response) |
| 19 |
} else { |
| 20 |
console.error("Missing API callback. Server response:") |
| 21 |
console.error(response) |
| 22 |
} |
| 23 |
}) |
| 24 |
} |