Created
June 22, 2017 02:30
-
-
Save lastday154/1f69bb7259165ee906751b1bff15cfe9 to your computer and use it in GitHub Desktop.
take advantages of recursive async
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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