Skip to content

Instantly share code, notes, and snippets.

@lastday154
Last active June 22, 2017 02:31
Show Gist options
  • Save lastday154/6086f91500a18ebd1f383a4e6a504bc8 to your computer and use it in GitHub Desktop.
Save lastday154/6086f91500a18ebd1f383a4e6a504bc8 to your computer and use it in GitHub Desktop.
Asynchronous request
// asynchronous request by using timer
// but not working when setInterval with 500, 100 < 1000
var messages = [];
var timer = setInterval(myTimer, 1000);
function myTimer() {
$.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) {
clearInterval(timer);
alert(messages.toString());
$("#result").append(messages.join('\n'));
}
})
.fail(function() {
alert( "can not get message from zalora");
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment