登录判读,并跳转到指定页面(window.location.href='http://localhost/index.html')

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
function confirm(){
   var tel=$tel.val(); //获取页面中登陆名和密码
   var pwd=$pwd.val();
   if (tel== "" || pwd== "" ){ //判断两个均不为空(其余判断规则在其输入时已经判断)
     alert( "手机号密码均不能为空!" )
     return false ;
   } else { //以上均符合要求,则调用登陆esb接口
      $.ajax({
        url:config.baseServerUrl + '/account/login' , //相对应的esb接口地址
        type: 'post'
        data:{mobile:tel,password:pwd}, //向服务器(接口)传递的参数
        success: function (data){ //服务器(接口)返回来的数据
          if (data.success){ //若是返回来的信息说明提交的信息为正确的
            var customerId = data.attr.customerInfo.id; //将数据中用户信息的ID赋值给变量
            sessionStorage.customerId = customerId; //将变量存储到本地sessionStorage中,而且value为customerID
            window.location.href= 'http://localhost/index.html' ;//正确登陆后页面跳转至
          }
          else { //若是返回来的信息说明提供的信息为错误的
            if (tel != data.tel){ //判断是用户名仍是密码错误,提示相应信息
              alert(data.message);
              $tel.val( "" );
              $pwd.val( "" );
              return false ;
             }
             if (pwd != data.pwd){
              alert(data.message);
              $pwd.val( "" );
              return false ;
             }
          }
        }
     })
   }
}
相关文章
相关标签/搜索