Last active
June 29, 2017 02:40
-
-
Save lastday154/3408744728bff9cfb24230eb91473d14 to your computer and use it in GitHub Desktop.
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
// 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