当我在 mui(this).button('loading'); 后使用ajax
按键的状态不会改变
是我漏了什么吗?
mui(document.body).on('tap', '.mui-btn',
function(e) {
mui(this).button('loading');
if(this.id === 'login') {
console.log('login');
mui.ajax('http://xxx/login.php', {
data: {
account: document.getElementById('account').toString(),
pwd: md5(document.getElementById('password').toString())
},
dataType: 'json', //服务器返回json格式数据
type: 'POST', //HTTP请求类型
async: false,
timeout: 10000, //超时时间设置为10秒;
success: function(data) {
console.log(data['type']);
if(data['type'] == 0) {
localStorage.setItem('session', data['session']);
if (document.getElementById('autoLoginValue').value == 1)
{
console.log('save user and password');
localStorage.setItem('userAccount', document.getElementById('account').value);
localStorage.setItem('userPassword', document.getElementById('password').value);
}else{
console.log('remove user and password');
localStorage.removeItem('userAccount');
localStorage.removeItem('userPassword');
}
session = localStorage.getItem('session');
console.log('login Success.');
stat = true;
} else {
//localStorage.remove('session');
console.log('login fail.');
stat = false;
};
},
error: function(xhr, type, errorThrown) {
//异常处理;
console.log('login error:')
console.log(xhr);
console.log(type);
console.log(errorThrown);
}
});
}
console.log('end');
mui(this).button('reset');
});
2 个回复
Trust - 少说废话
ajax 请求结束后,需要调整组件的状态,不会自动变化的。
在 success 回调中,重置。
l***@brain-c.com (作者) - 不务正业的男人
发现我的例子有没有把button 定义好...
我分别在下面几次点输出了 consone.log
[Web浏览器] "login" /HelloHBuilder/users/login.html (157)
[Web浏览器] "0" /HelloHBuilder/users/login.html (168)
[Web浏览器] "remove user and password" /HelloHBuilder/users/login.html (178)
[Web浏览器] "login Success." /HelloHBuilder/users/login.html (184)
[Web浏览器] "end" /HelloHBuilder/users/login.html (203)