livedj-app/src/web/request.js
2023-08-03 19:20:27 +02:00

65 lines
1.6 KiB
JavaScript
Executable File

function httpGetAsync(url, callback) {
const xmlHttp = new XMLHttpRequest();
xmlHttp.onreadystatechange = function () {
if (xmlHttp.readyState === 4)
{
try {
callback(JSON.parse(xmlHttp.responseText), xmlHttp.status);
} catch( e )
{
callback({}, 500);
}
}
}
xmlHttp.open("GET", url, true); // true for asynchronous
xmlHttp.send(null);
}
function httpPostAsync(url, data, callback) {
const xmlHttp = new XMLHttpRequest();
xmlHttp.onreadystatechange = function () {
if (xmlHttp.readyState === 4)
try {
callback(JSON.parse(xmlHttp.responseText), xmlHttp.status);
} catch( e )
{
callback({}, 500);
}
}
xmlHttp.open("POST", url, true); // true for asynchronous
xmlHttp.setRequestHeader("Content-Type", "application/json");
xmlHttp.send(JSON.stringify(data));
}
const modal = document.getElementById("myModal");
const modal_title = document.getElementById("modal-title");
const modal_text = document.getElementById("modal-text");
let last_add = 0;
// Get the <span> element that closes the modal
const modal_span = document.getElementsByClassName("close")[0];
// When the user clicks on <span> (x), close the modal
modal_span.onclick = function() {
modal.style.display = "none";
}
// When the user clicks anywhere outside of the modal, close it
window.onclick = function(event) {
if (event.target === modal) {
modal.style.display = "none";
}
}
function openModal(title,text)
{
modal_title.innerText = title;
modal_text.innerHTML = text;
modal.style.display = "block"
}