Updating xhr request
* Querying when request has failed * Added a maximum consecutive query parameter to limit query when server has shutdown * By default I've put it to -1 (no maximum), it can be modified * Stopping with an error when too many failed query * Removing log message in torrents.js
Cette révision appartient à :
Parent
e52ee35cac
révision
133947df0a
2 fichiers modifiés avec 10 ajouts et 2 suppressions
|
@ -1,4 +1,6 @@
|
|||
var Query = {
|
||||
Failed:0,
|
||||
MaxConsecutingFailing:-1,
|
||||
Get: function(url, renderer, callback) {
|
||||
var xhr = new XMLHttpRequest();
|
||||
console.log(url)
|
||||
|
@ -6,8 +8,15 @@ var Query = {
|
|||
xhr.responseType = 'json';
|
||||
xhr.onload = function(e) {
|
||||
if (this.status == 200) {
|
||||
Query.Failed = 0;
|
||||
renderer(this.response);
|
||||
callback(this.response)
|
||||
callback(this.response);
|
||||
} else {
|
||||
console.log("Error when refresh")
|
||||
Query.Failed++;
|
||||
console.log("Attempt to refresh "+Query.Failed+"...");
|
||||
if ((Query.MaxConsecutingFailing == -1) || (Query.Failed < Query.MaxConsecutingFailing)) Query.Get();
|
||||
else console.error("Too many attempts, stopping...")
|
||||
}
|
||||
};
|
||||
xhr.send();
|
||||
|
|
|
@ -12,7 +12,6 @@ var Torrents = {
|
|||
},
|
||||
Refresh: function() {
|
||||
if (this.CanRefresh) {
|
||||
console.log("Start Refresh...")
|
||||
this.timeout = setTimeout(function() {
|
||||
var searchArgs = (window.location.search != "") ? window.location.search.substr(1) : ""
|
||||
searchArgs = (Torrents.LastID > 0) ? "?fromID="+Torrents.LastID+"&"+searchArgs : "?"+searchArgs
|
||||
|
|
Référencer dans un nouveau ticket