diff options
author | maheshgudi | 2017-11-22 20:49:07 +0530 |
---|---|---|
committer | maheshgudi | 2017-11-22 20:49:07 +0530 |
commit | 7e2972786599fc23c436e593fcc236defd93c88c (patch) | |
tree | 777293efb56c5ec9a9f2e774ac98dafbde2f0eb6 /yaksh/static | |
parent | fa0548170cb8ee68508bc7286c65f9651f5718a1 (diff) | |
download | online_test-7e2972786599fc23c436e593fcc236defd93c88c.tar.gz online_test-7e2972786599fc23c436e593fcc236defd93c88c.tar.bz2 online_test-7e2972786599fc23c436e593fcc236defd93c88c.zip |
Display error output without reloading.
Diffstat (limited to 'yaksh/static')
-rw-r--r-- | yaksh/static/yaksh/js/requesthandler.js | 43 |
1 files changed, 40 insertions, 3 deletions
diff --git a/yaksh/static/yaksh/js/requesthandler.js b/yaksh/static/yaksh/js/requesthandler.js index 7ff90df..1c9a290 100644 --- a/yaksh/static/yaksh/js/requesthandler.js +++ b/yaksh/static/yaksh/js/requesthandler.js @@ -53,16 +53,53 @@ function response_handler(method_type, content_type, data, uid){ } else if(content_type.indexOf("application/json") !== -1) { res = JSON.parse(data); request_status = res.status; - if(method_type === "POST") { - uid = res.uid; + if (request_status){ + if(method_type === "POST") { + uid = res.uid; + } + check_state(request_status, uid); + } + else{ + unlock_screen(); + error_array = res.error; + generic_error(error_array) + } - check_state(request_status, uid); } else { reset_values(); unlock_screen(); } } +function generic_error(error_array){ + var error_output = document.getElementById("error_panel"); + error_output.innerHTML = "" + for (var i = 0; i < error_array.length; i++) { + var panel_danger = document.createElement('div'); + panel_danger.setAttribute('class', "panel panel-danger"); + + var panel_heading = document.createElement('div'); + panel_heading.setAttribute('class', "panel-heading"); + panel_heading.innerHTML = "Error no. " + (i + 1); + + var panel_body = document.createElement('div'); + panel_body.setAttribute('class', "panel-body"); + + var well = document.createElement('div'); + well.setAttribute('class', "well well-sm"); + + var pre = document.createElement('pre'); + var code = document.createElement('code'); + console.log(error_array[i]) + code.append(error_array[i]); + pre.appendChild(code); + well.appendChild(pre); + panel_body.appendChild(well); + panel_danger.appendChild(panel_heading); + panel_danger.appendChild(panel_body); + error_output.appendChild(panel_danger); + } +} function ajax_check_code(url, method_type, data_type, data, uid) { $.ajax({ method: method_type, |