Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
a sample ajax chunk request using deferreds
var getAllObjects = function () {
var start = 0,
chunkSize = 2000,
dfd = $.Deferred(),
getChunk = function (start, chunkSize) {
return $.ajax({
url: '<requesturi>',
type: 'POST',
dataType: 'json',
data: JSON.stringify({ start: start, length: chunkSize }),
contentType: 'application/json; charset=utf-8'
});
},
recursiveGet = function () {
getChunk(start, chunkSize).success(function (retVal) {
if (checkRetCode(retVal.retCode)) {
if (start === 0) {
handleFirst(retVal.data);
}
else {
handleChunk(retVal.data);
}
if (retVal.objectCount < chunkSize) {
dfd.resolve();
}
else {
start += chunkSize + 1;
recursiveGet();
}
}
else {
dfd.resolve();
}
});
};
recursiveGet();
return dfd;
};
getAllObjects().then(function () { window.alert("success"); });
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment