Merge pull request #861 from NyaaPantsu/xhr-torrent-refresh
Xhr torrent refresh
Cette révision appartient à :
révision
face67892b
2 fichiers modifiés avec 10 ajouts et 3 suppressions
|
@ -1,13 +1,21 @@
|
||||||
var Query = {
|
var Query = {
|
||||||
|
Failed:0,
|
||||||
|
MaxConsecutingFailing:-1,
|
||||||
Get: function(url, renderer, callback) {
|
Get: function(url, renderer, callback) {
|
||||||
var xhr = new XMLHttpRequest();
|
var xhr = new XMLHttpRequest();
|
||||||
console.log(url)
|
|
||||||
xhr.open('GET', url, true);
|
xhr.open('GET', url, true);
|
||||||
xhr.responseType = 'json';
|
xhr.responseType = 'json';
|
||||||
xhr.onload = function(e) {
|
xhr.onload = function(e) {
|
||||||
if (this.status == 200) {
|
if (this.status == 200) {
|
||||||
|
Query.Failed = 0;
|
||||||
renderer(this.response);
|
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(url, renderer, callback);
|
||||||
|
else console.error("Too many attempts, stopping...")
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
xhr.send();
|
xhr.send();
|
||||||
|
|
|
@ -12,7 +12,6 @@ var Torrents = {
|
||||||
},
|
},
|
||||||
Refresh: function() {
|
Refresh: function() {
|
||||||
if (this.CanRefresh) {
|
if (this.CanRefresh) {
|
||||||
console.log("Start Refresh...")
|
|
||||||
this.timeout = setTimeout(function() {
|
this.timeout = setTimeout(function() {
|
||||||
var searchArgs = (window.location.search != "") ? window.location.search.substr(1) : ""
|
var searchArgs = (window.location.search != "") ? window.location.search.substr(1) : ""
|
||||||
searchArgs = (Torrents.LastID > 0) ? "?fromID="+Torrents.LastID+"&"+searchArgs : "?"+searchArgs
|
searchArgs = (Torrents.LastID > 0) ? "?fromID="+Torrents.LastID+"&"+searchArgs : "?"+searchArgs
|
||||||
|
|
Référencer dans un nouveau ticket