登錄判讀,並跳轉到指定頁面(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 ;
             }
          }
        }
     })
   }
}
相關文章
相關標籤/搜索