Auto adjusting AJAX timeout when polling for the progress JSON closes #45

pull/73/head
jonsowman 2010-06-19 23:35:25 +01:00
rodzic 3426f76518
commit d21417dd0c
2 zmienionych plików z 36 dodań i 4 usunięć

Wyświetl plik

@ -1,4 +1,17 @@
<?php
/*
* CUSF Landing Prediction Version 2
* http://www.cuspaceflight.co.uk
*
* Jon Sowman 2010
* jon@hexoc.com
* http://www.hexoc.com
*
* http://github.com/jonsowman/cusf-standalone-predictor
*
*/
require_once("includes/functions.inc.php");
// get the time for pre-populating the form
$time = time() + 3600;
@ -32,6 +45,9 @@ var land_img = "images/target-8-sm.png";
var burst_img = "images/pop-marker.png";
var clickListener;
var clickMarker;
var ajaxTimeout = 500;
var maxAjaxTimeout = 2000;
var deltaAjaxTimeout = 100;
</script>
</head>

Wyświetl plik

@ -172,10 +172,26 @@ function getJSONProgress(pred_uuid) {
$.ajax({
url:"preds/"+pred_uuid+"/progress.json",
dataType:'json',
timeout: 1000,
// complete: function(data, httpstatus) {
// appendDebug(httpstatus);
// },
timeout: ajaxTimeout,
error: function(xhr, status, error) {
if ( status == "timeout" ) {
appendDebug("Polling for progress JSON timed out");
// check that we haven't reached maximum allowed timeout
if ( ajaxTimeout < maxAjaxTimeout ) {
// if not, add the delta to the timeout value
newTimeout = ajaxTimeout + deltaAjaxTimeout;
appendDebug("Increasing AJAX timeout from " + ajaxTimeout
+ "ms to " + newTimeout + "ms");
ajaxTimeout = newTimeout;
} else {
// otherwise, throw an error and kill the poller
clearInterval(ajaxEventHandle);
appendDebug("Reached maximum ajaxTimeout value of " + maxAjaxTimeout);
throwError("Tried increasing the AJAX polling timeout to "+maxAjaxTimeout
+"ms but the request still timed out.");
}
}
},
success: processProgress
});
}