From d108cd03e446dcac2b4eeeaec1ea17c47b205c78 Mon Sep 17 00:00:00 2001 From: prathamesh Date: Thu, 17 Aug 2017 10:52:25 +0530 Subject: Fixed a bug related to GET request after every 2 seconds Also added a count to limit GET request So now for a given question, maximum GET request is 15. After 15 requests, if server still does not give the desired response then the request loop will break. --- yaksh/static/yaksh/js/requesthandler.js | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/yaksh/static/yaksh/js/requesthandler.js b/yaksh/static/yaksh/js/requesthandler.js index d463434..f653da1 100644 --- a/yaksh/static/yaksh/js/requesthandler.js +++ b/yaksh/static/yaksh/js/requesthandler.js @@ -1,17 +1,22 @@ request_status = "initial" +count = 0; function submitRequest(){ document.forms["code"].submit(); } function check_state(state, uid) { - if (state == "running" || state == "not started") { - setTimeout(get_result(uid), 2000); + if ((state == "running" || state == "not started") && count < 15) { + count++; + setTimeout(function() {get_result(uid);}, 2000); } else if (state == "unknown") { request_status = "initial"; + count = 0; notify("You are requesting for a wrong data"); unlock_screen(); } else { request_status = "initial"; + count = 0; + notify("Please try after few minutes"); unlock_screen(); } } @@ -49,11 +54,13 @@ function get_result(uid){ check_state(request_status, uid); } else { request_status = "initial"; + count = 0; unlock_screen(); } }, error: function(xhr, text_status, error_thrown ) { request_status = "initial"; + count = 0; unlock_screen(); notify("There is some problem. Try later.") } @@ -106,6 +113,7 @@ $(document).ready(function(){ content_type = xhr.getResponseHeader("content-type"); if(content_type.includes("text/html")) { request_status = "initial" + count = 0; unlock_screen(); document.open(); document.write(data); @@ -117,11 +125,13 @@ $(document).ready(function(){ check_state(request_status, uid); } else { request_status = "initial"; + count = 0; unlock_screen(); } }, error: function(xhr, text_status, error_thrown ) { request_status = "initial"; + count = 0; unlock_screen(); notify("There is some problem. Try later.") } -- cgit