X-Git-Url: https://git.cworth.org/git?a=blobdiff_plain;f=lmno.js;h=e4785a86d4fe8ae282ae2102a3c3bebaf2b8f414;hb=36670ada413f81ed9591e63d72309c5e0fffb027;hp=f1f9cd7f874a1f193382283a5a6a350deefc0b74;hpb=eca2d3b07461385192c12c68b83e658ce366d09f;p=lmno.games diff --git a/lmno.js b/lmno.js index f1f9cd7..e4785a8 100644 --- a/lmno.js +++ b/lmno.js @@ -30,3 +30,26 @@ function lmno_join(form) { form.reset(); } + +function new_loadend() { + if (this.status == 200) { + /* Response contains the game ID which we simply point the browser to. */ + const game_id = JSON.parse(this.response); + window.location.href = ('/' + game_id); + return; + } + + add_message("danger", `An error occured creating a new game (${this.status}).`); +} + +function lmno_new(engine) { + console.log("In lmno_new"); + const request = new XMLHttpRequest(); + request.addEventListener("loadend", new_loadend); + + request.open("POST", "/new/" + engine); + request.setRequestHeader("Content-Type", "application/json; charset=UTF-8"); + request.send(); + + return false; +}