diff --git a/app/frontend/templates/panel/server_term.html b/app/frontend/templates/panel/server_term.html index bb63fbe7..a127e7aa 100644 --- a/app/frontend/templates/panel/server_term.html +++ b/app/frontend/templates/panel/server_term.html @@ -164,7 +164,7 @@ const serverId = new URLSearchParams(document.location.search).get('id') - function send_command(serverId, command) { + async function send_command(serverId, command) { if (command == 'start_server') { startBtn.setAttribute('disabled', 'disabled'); restartBtn.removeAttribute('disabled'); @@ -178,16 +178,23 @@ // const token = getCookie("_xsrf"); - $.ajax({ - type: "POST", - headers: { 'X-XSRFToken': token }, - url: `/api/v2/servers/${serverId}/action/${command}`, - success: function (data) { - console.log("got response:"); - console.log(data); - } + let res = await fetch(`/api/v2/servers/${serverId}/action/${command}`, { + method: 'POST', + headers: { + 'token': token, + }, }); + let responseData = await res.json(); + if (responseData.status === "ok") { + console.log("Command received successfully") + } else { + bootbox.alert({ + title: responseData.status, + message: responseData.error + }); + } } + if (webSocket) { webSocket.on('update_button_status', function (updateButton) { if (updateButton.isUpdating) {