代码如下: var tepCookie = 1;
$.post("/1/user/login", {type:4, getFlag:1}, function(data) {
if(!data) {
alert(111);
tepCookie = 2;
}
}); alert(tepCookie);这个AJAX肯定是调用成功了,因为可以弹出“111”,但是为什么tepCookie赋值总是赋不上呢???谢谢!
$.post("/1/user/login", {type:4, getFlag:1}, function(data) {
if(!data) {
alert(111);
tepCookie = 2;
}
}); alert(tepCookie);这个AJAX肯定是调用成功了,因为可以弹出“111”,但是为什么tepCookie赋值总是赋不上呢???谢谢!
$("body").ajaxStop(function(){
alert(tepCookie);
}); 你加入这段话就明白了 。
当ajax函数还没执行完 就已经alert了 。
async: false
tepCookie = 2;这里还没赋值alert(tepCookie);就先执行了
var tepCookie = 1;
$.post("/1/user/login", {type:4, getFlag:1}, function(data) {
if(!data) {
alert(111);
tepCookie = 2;
tepArr[0](tepCookie);
tepArr = [];
}
});
function getTepCoo(fn){
tepArr.push(fn);
}
getTepCoo(function(tepCookie){
alert(tepCookie);
});