这是我注册页面的代码
var mobile = document.getElementById("mobile").value;
var verify_code = document.getElementById("verify").value;
// var invite = document.getElementById("invite").value;
var password = document.getElementById("password").value;
if(mobile == "")
{
mui.toast("请输入手机号!");
return false;
}
if(verify_code == "")
{
mui.toast("请输入验证码!");
return false;
}
if(password == "")
{
mui.toast("请输入密码!");
return false;
}
var _mobile_token = common.getUserInfo('_mobile_token');
var data = {mobile:mobile, password:password, code:verify_code, _mobile_token:_mobile_token};
common.request('/console/register', data, 'post',function(data){
if(data.status == 1)
{
mui.alert(data.info,function(){
mui.back();
})
}
else
{
mui.toast(data.info);
}
});
});
var sendCodeBtn = document.getElementById("send-code");
sendCodeBtn.addEventListener("tap",function(){
var mobile = document.getElementById("mobile").value;
if ( mobile == '' ) {
mui.toast("请输入手机号!");
return false;
}
common.request_callback_success = function(data){
common.setUserInfo('_mobile_token', data.info['_mobile_token']);
mui.toast('短信验证码已下发至您的手机,请注意查收');
time(sendCodeBtn);
common.request_func_reset();//回调函数复位
}
common.request('/sms/send', {type:'register', 'mobile':mobile}, 'post');
});
这是我js代码
/**
-
复位回调方法
*/
owner.request_func_reset = function(func) {if (typeof func == 'undefined'|| func == '' ) { func = 'ALL'; } if (func == 'ALL') { owner.request_callback_success = function(data) { if (typeof data.info == 'string') { mui.alert(data.info); } else { mui.alert('处理成功!'); } } owner.request_callback_fail = function(data) { mui.toast(data.info); } } else if (func == 'fail') { owner.request_callback_fail = function(data) { mui.toast(data.info); } } else { owner.request_callback_success = function(data) { if (typeof data.info == 'string') { mui.alert(data.info); } else { mui.alert('处理成功!'); } } } owner.request_callback = function(data) { if (data.status == 0) { owner.request_callback_fail(data) } else { owner.request_callback_success(data) } }
}
owner.request = function(url, data, type, func, login_fail_func) {
mui.plusReady(function() {
var callargs = arguments;
mui.ajaxSettings = mui.extend(mui.ajaxSettings, {
xhr: function(settings) {
return new plus.net.XMLHttpRequest();
}
});
// mui.ajaxSettings.xhr = function() {
// return new window.XMLHttpRequest();
// };if (typeof data['_token'] == 'undefined') { data['_token'] = owner.getUserInfo('_token'); } if (url[0] != '/') { url = owner.host + owner.version + "/" + url; } else { url = owner.host + owner.version + url; } // alert(typeof(func)) var _callback; if (typeof(func) == "function") { _callback = func; // alert('ok2'); } else { _callback = owner.request_callback; } owner.log(url); mui.ajax(url, { crossDomain: true, data: data, dataType: 'json', //服务器返回json格式数据 type: type, //HTTP请求类型 timeout: 10000, //超时时间设置为10秒; // headers:{'Content-Type':'application/json'}, success: function(data) { if (data.status == 3) { if (typeof(login_fail_func) == 'function') { login_fail_func(); } else { mui.openWindow({ url: "../login.html", id: "../login.html", waiting: { autoShow: false } }) } } else { //common.log(data); _callback(data, callargs); // owner.request_func_reset(); } }, error: function(xhr, type, errorThrown) { //异常处理; mui.toast('网络错误'+type) console.info(xhr); console.info(type); owner.log(errorThrown); } }); });
}
owner.request_console = function(url, data, type, func, login_fail_func) {
if (url[0] != '/') {
url = '/console/' + url;
} else {
url = '/console' + url;
}data['_token'] = owner.getUserInfo('_token'); owner.request(url, data, type, func, login_fail_func);
}
owner.log = function(data) {
console.log(JSON.stringify(data));
}
求助 帮忙 谢谢~~~~图片是我第一次注册的效果 再次获取验证码后就能注册成功。。