X-Git-Url: https://git.cworth.org/git?p=lmno.games;a=blobdiff_plain;f=lmno.js;fp=lmno.js;h=e4785a86d4fe8ae282ae2102a3c3bebaf2b8f414;hp=f1f9cd7f874a1f193382283a5a6a350deefc0b74;hb=c2b3628fe854407ea6782e8c736df16b9c6719dc;hpb=eebce34d59985154e68c04456f09b6a0ff321f91 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; +}