From cbe6af7349c81d167db30e7c7f62cfc52c9343d8 Mon Sep 17 00:00:00 2001 From: Jeff Becker Date: Sat, 30 Sep 2017 08:15:55 -0400 Subject: [PATCH] mor js --- contrib/static/overchan.js | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/contrib/static/overchan.js b/contrib/static/overchan.js index d288fad..b262c5c 100644 --- a/contrib/static/overchan.js +++ b/contrib/static/overchan.js @@ -52,20 +52,21 @@ onready(function() { var ajax = new XMLHttpRequest(); ajax.onreadystatechange = function() { if (ajax.readyState == 4) { + var err = "unknown error"; + var j = null; + try { + j = JSON.parse(ajax.responseText); + err = j.error || err; + } catch (ex) { + err = "error parsing reply: "+ ex; + } if(ajax.status == 201) { // success - cb(null); + cb(null, j); } else if (ajax.status == 200) { - var err = "unknown error"; - try { - var j = JSON.parse(ajax.responseText); - err = j.error || err; - } catch (ex) { - err = "error parsing reply: "+ ex; - } - cb(err); + cb(err, j); } else { - cb("http "+ajax.status); + cb("http "+ajax.status, j); } } else { elem.innerHTML += "."; @@ -86,9 +87,9 @@ onready(function() { e.onclick = function() { e.disabled = true; e.innerHTML = "posting "; - submitPost(document.forms[0], e, function(err) { + submitPost(document.forms[0], e, function(err, j) { var msg = err || "posted"; - console.log(msg); + console.log(msg, j); e.innerHTML = msg; setTimeout(function() { e.disabled = false;