summaryrefslogtreecommitdiff
path: root/yaksh/static
diff options
context:
space:
mode:
authorprathamesh2017-08-17 10:52:25 +0530
committerprathamesh2017-08-17 10:52:25 +0530
commitd108cd03e446dcac2b4eeeaec1ea17c47b205c78 (patch)
tree0f37caa3448f23086d3da3b5f1ef199ca5a69309 /yaksh/static
parentf730a531cf041620209abb812792080cb2d63b4d (diff)
downloadonline_test-d108cd03e446dcac2b4eeeaec1ea17c47b205c78.tar.gz
online_test-d108cd03e446dcac2b4eeeaec1ea17c47b205c78.tar.bz2
online_test-d108cd03e446dcac2b4eeeaec1ea17c47b205c78.zip
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.
Diffstat (limited to 'yaksh/static')
-rw-r--r--yaksh/static/yaksh/js/requesthandler.js14
1 files 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.")
}