Last active
June 22, 2017 02:31
-
-
Save lastday154/6086f91500a18ebd1f383a4e6a504bc8 to your computer and use it in GitHub Desktop.
Asynchronous request
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 = []; | |
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