假设我想通过清除 cookie 来登录和注销
function clearCookies() {
...
}
function login(username,password) {
$.post(...).then(function(result){
if(result == 1) {
create();
}
else {
login(username, password);
}
})
}
function create() {
$.post(...).then(function(result){
// create
})
}
clearCookies
当我遍历用户名时应该在哪里插入函数。
var data = [{"username":"_iamnumber4","password":"four"},{"username":"superman","password":"fantasic"}]
var promises = [];
$.each(data, function(k,v){
promises.push(login(v.username, v.password));
});
$.when.apply($, promises).done(function() {
console.log('all done');
});