mirror of
https://github.com/Doodle3D/doodle3d-connect.git
synced 2024-12-25 18:13:48 +01:00
added fetch and fetchHeader in ServerAPI
This commit is contained in:
parent
0f8e84016e
commit
f8084b59d9
@ -27,12 +27,56 @@ function ServerAPI() {
|
||||
if (completeHandler) completeHandler(response);
|
||||
}
|
||||
}).fail(function(response) {
|
||||
console.log("fail");
|
||||
if (failedHandler) failedHandler();
|
||||
if (failedHandler) failedHandler(response.responseJSON);
|
||||
});
|
||||
};
|
||||
|
||||
// '/fetch/'+uid.value+'/'+line.value;
|
||||
this.fetch = function(uuid, chunk, completeHandler, failedHandler) {
|
||||
console.log("ServerAPI:fetch",uuid,chunk);
|
||||
|
||||
if (!uuid) {
|
||||
console.log("Server.fetch failed: no uuid");
|
||||
if (failedHandler) failedHandler();
|
||||
return;
|
||||
}
|
||||
|
||||
if (!chunk) {
|
||||
chunk = 0;
|
||||
}
|
||||
|
||||
$.ajax({
|
||||
url: _apiURL + "/fetch/" + uuid + "/" + chunk,
|
||||
type: "GET",
|
||||
dataType: 'text', //no json but text
|
||||
timeout: _timeoutTime,
|
||||
cache: false,
|
||||
success: function(response) {
|
||||
if (completeHandler) completeHandler(response);
|
||||
}
|
||||
}).fail(function(response) {
|
||||
console.log("ServerAPI:fetch fail response:",response);
|
||||
if (failedHandler) failedHandler(response.responseJSON);
|
||||
});
|
||||
};
|
||||
|
||||
this.fetchHeader = function(uuid,completeHandler,failedHandler) {
|
||||
this.fetch(uuid,0,function(successData) {
|
||||
console.log("_serverAPI fetchHeader");
|
||||
if (successData) {
|
||||
var items = successData.split("\n");
|
||||
try {
|
||||
var headerText = items[0].substr(1);
|
||||
var headerJSON = JSON.parse(headerText);
|
||||
// console.log("fetchHeader",headerJSON)
|
||||
if (completeHandler) completeHandler(headerJSON);
|
||||
} catch (e) {
|
||||
console.log("fetchHeader failed to parse JSON",e);
|
||||
if (failedHandler) failedHandler();
|
||||
}
|
||||
}
|
||||
}, function(failData) {
|
||||
console.log("_serverAPI fetchHeader failed",failData);
|
||||
});
|
||||
};
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user