Skip to content

Instantly share code, notes, and snippets.

@lastday154
Created June 22, 2017 02:30
Show Gist options
  • Save lastday154/1f69bb7259165ee906751b1bff15cfe9 to your computer and use it in GitHub Desktop.
Save lastday154/1f69bb7259165ee906751b1bff15cfe9 to your computer and use it in GitHub Desktop.
take advantages of recursive async
// take advantages of recursive async
function getMessages(maxMessage) {
var messages = [];
function getNextMessage() {
$.ajax({
url: 'https://www.zalora.sg/ajax/catalog/justforyou/?feedName=recentlyviewed&brandName=&size=20&category=&userId=10214339066013667&engine=datajet',
method: 'GET',
async: true,
success: function(msg) {
if (messages.length < maxMessage) {
if (messages.indexOf(msg) == -1) {
messages.push(msg);
}
getNextMessage();
} else {
console.log(messages);
}
}
});
}
getNextMessage();
}
getMessages(3);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment