Skip to content

Instantly share code, notes, and snippets.

@novalagung
Created January 21, 2019 07:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save novalagung/6d26d80357c88874e80a91abfc81e8fe to your computer and use it in GitHub Desktop.
Save novalagung/6d26d80357c88874e80a91abfc81e8fe to your computer and use it in GitHub Desktop.
var vm = {}
vm.dataUser = []
vm.isDataUserReady = false
vm.doGetData = function() {
$.ajax({
url: "https://reqres.in/api/users?page=2"
}).then(function(res) {
setTimeout(() => {
vm.dataUser = res.data
vm.isDataUserReady = true
}, 2000)
})
}
vm.doSomeProcess = function() {
console.log("hello")
console.log("test")
var doWait = setInterval(function() {
if (!vm.isDataUserReady) {
return
}
clearInterval(doWait)
// put all process here
// example below:
var sample = vm.dataUser
if (sample.length > 0) {
alert("data arrived")
}
}, 300)
}
$(function() {
vm.doGetData()
vm.doSomeProcess()
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment