在做一个登录页面,想要通过ajax来验证账号密码,在页面输入账号密码后,根据返回的data.status来跳转页面或错误提示。
我的问题是:
1.在以下代码中的data.status是怎么规定的
2.在没有后台接口的情况下,怎么测试ajax写得对不对,或者怎么利用mock来测试(实在相当的小白,看了mock教程看不懂)
3.各位大神方便的话,能不能告诉我改怎么起步开始学js,就是ajax这些
这是我在网上看到的代码整合自己需要写的js文件
$("#loginBtn").click(function (){
var userId=$("#userId");
var userPass=$("#userPass");
// 判断输入框为空
if(userId.val()==""||userPass.val()==""){
userId.focus();
console.log("hah");
$('#errormsg').html("<strong>用户名或密码不能为空!<strong>");
return false;
}
else{
$.ajax({
url:loginController,
data:{"userId":userId.val(),"userPass":userPass.val()},
type:"post",
dataType:"json",
success:function(data){
if(data.status=="1"){
window.location.href="proMng.html";
}
else if(data.status=="0"){
$("errormsg").html("<strong>用户名或密码错误</strong>");
}
},
error:function(data){
console.log("出错:"+data.code);
}
});
}
});
麻烦各位大神为我解答,谢谢啦谢谢啦