From 49615e5a24ecfdd0b22bae080e7f9bb2507bbfd7 Mon Sep 17 00:00:00 2001 From: prathamesh Date: Mon, 14 Aug 2017 14:51:39 +0530 Subject: To handle unknown status response from code server --- yaksh/static/yaksh/js/requesthandler.js | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'yaksh/static') diff --git a/yaksh/static/yaksh/js/requesthandler.js b/yaksh/static/yaksh/js/requesthandler.js index 9d023cc..b637928 100644 --- a/yaksh/static/yaksh/js/requesthandler.js +++ b/yaksh/static/yaksh/js/requesthandler.js @@ -3,9 +3,15 @@ function submitRequest(){ document.forms["code"].submit(); } -function check_state(state, uid, success) { - if (state == "running") { +function check_state(state, uid) { + if (state == "running" || state == "not started") { setTimeout(get_result(uid), 2000); + } else if (state == "unknown") { + request_status = "initial"; + var $notice = document.getElementById("notification"); + $notice.classList.add("alert"); + $notice.classList.add("alert-success"); + $notice.innerHTML = "Your are requesting for a wrong data"; } } @@ -24,7 +30,7 @@ function get_result(uid){ } else if(content_type.includes("application/json")) { res = JSON.parse(data); request_status = res.status; - check_state(request_status, uid, res.success); + check_state(request_status, uid); } } }); @@ -74,6 +80,7 @@ $(document).ready(function(){ success: function(data, status, xhr) { content_type = xhr.getResponseHeader("content-type"); if(content_type.includes("text/html")) { + request_status = "initial" document.open(); document.write(data); document.close(); @@ -81,7 +88,7 @@ $(document).ready(function(){ res = JSON.parse(data); var uid = res.uid; request_status = res.state; - check_state(request_status, uid, false); + check_state(request_status, uid); } } }); -- cgit