function callPostUrl(url, jsonData, verbose = true) {
if (verbose) console.log("GET " + url + " with data " + jsonData.toString());
return new Promise(function(resolve, reject) {
var xhr = new XMLHttpRequest();
var dest = url;
const data = JSON.stringify(jsonData);
if (verbose) console.log("Sending data " + data)
xhr.open("POST", dest);
xhr.setRequestHeader("Content-Type", "application/json");
xhr.onreadystatechange = function () {
if (xhr.readyState === 4) {
console.log("Got response " + xhr.responseText);
console.log("Status " + xhr.status);
if (xhr.status != 200) {
reject("Error!");
}
resolve(JSON.parse(xhr.responseText));
}
};
try {
console.log("Sending " + jsonData.toString());
xhr.send(data);
} catch(e) {
if (verbose) console.log("Error " + e);
reject(e)
}
return "Doing POST on " + url
});
}