userform.addEventListener("submit", function(e){
// 判断用户名是否为空,如果为空则让其获得焦点
if (!app.isNotNull(username.value)) {
// 获取焦点
username.focus();
} else if (!app.isNotNull(txt_password.value)) {
// 获取焦点
txt_password.focus();
} else {
// 判断用户名和密码的长度,进行限制
if (username.value.length > 12) {
app.showToast("用户名不能超过12", "error");
return false;
} else if (txt_password.value.length > 12) {
app.showToast("密码不能超过12", "error");
return false;
}
app.showToast(app.serverUrl, "error");
// 获取每台手机的唯一cid
var cid = plus.push.getClientInfo().clientid;
// 与后端联调
// app.serverUrl = http://10.10.10.123:8080
mui.ajax(app.serverUrl + "/user/registOrLogin",{
data:{
username:username.value,
password:txt_password.value,
cid: cid
},
dataType:'json',//服务器返回json格式数据
type:'post',//HTTP请求类型
timeout:10000,//超时时间设置为10秒;
headers:{'Content-Type':'application/json'},
success:function(data){
//服务器返回响应,根据响应结果,分析是否登录成功;
console.log(JSON.stringify(data));
}
});
}
// 阻止默认事件,阻止默认表单提交
e.preventDefault();
});