0
订购
中的任何想法,为什么下面的代码:的onload功能烧制出来
<script>
var access_token;
var access_token_secret;
function Login(){
img = document.getElementById('authenticate');
img.src = 'authenticate.png';
login = document.getElementById('login');
login.style.visibility="visible";
}
function cookieHandlerStep1(){
chrome.cookies.get({
url:URL_GOES_HERE,
name:'access_token'
},
function(cookie){
if(cookie){
access_token = cookie['value'];
cookieHandlerStep2();
} else{
Login();
}
});
}
function cookieHandlerStep2(){
chrome.cookies.get({
url:URL_GOES_HERE,
name:'access_token_secret'
},
function(cookie){
if(cookie){
access_token_secret = cookie['value'];
Interact();
} else{
Login();
}
});
}
function Interact(){
alert(access_token);
xhr = new XMLHttpRequest();
xhr.open("GET", URL_GOES_HERE, true);
xhr.onreadystatechange = function() {
if (xhr.readyState == 4) {
document.write(xhr.responseText);
}
}
xhr.send();
}
</script>
<body onload="cookieHandlerStep1(),cookieHandlerStep2(),Interact()">
能可能有序列的执行的职能?
这是非常有帮助。 但是,我忘了完全编辑代码。 最新代码中的CookieHandlerStep1不会触发CookieHandlerStep2。 CookieHandlerStep2也不会触发Interact()。 我认为你所说的重要思想是,回调不保证在代码的其余部分之前被调用。 我发生了什么事情(在我编辑每个函数以调用链中的下一个函数之前),是Interact()正在发射,然后是CookieHandlerStep1(),最后是CookieHandlerStep2()。 你能解释一下关于为什么在下一个func之前回调函数没有被执行吗? – 2011-02-15 07:13:20