Skip to content

Instantly share code, notes, and snippets.

@lastday154
Last active June 29, 2017 02:40
Show Gist options
  • Save lastday154/3408744728bff9cfb24230eb91473d14 to your computer and use it in GitHub Desktop.
Save lastday154/3408744728bff9cfb24230eb91473d14 to your computer and use it in GitHub Desktop.
// asynchronous request by using timer
// but not working when setInterval with 500, 100 < 1000
var messages = [];
function getMessages() {
$.ajax({
url: 'https://www.zalora.sg/ajax/catalog/justforyou/?feedName=recentlyviewed&brandName=&size=20&category=&userId=10214339066013667&engine=datajet'
})
.done(function(msg){
if(messages.indexOf(msg) == -1) {
messages.push(msg);
}
if (messages.length >= 3) {
console.log(messages);
$("#result").append(messages.join('\n'));
}
})
.fail(function() {
alert( "can not get message from zalora");
});
}
var i=0;
while( i<3) {
setTimeout(getMessages, 0); i++;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment