Skip to content

Instantly share code, notes, and snippets.

@tkarpinski
Created June 27, 2011 15:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tkarpinski/1049066 to your computer and use it in GitHub Desktop.
Save tkarpinski/1049066 to your computer and use it in GitHub Desktop.
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