js JSONP实例

<script type="text/javascript">
    $(function(){         
        checkuserstatus();     
     $('#loginbutton').click(function(){
         var loginpwd=$('#password').val();
        var username=$('#username').val();
        var code=$('#verification').val();
        $("#fastloginspan").html('');
        $("#msg").html("");
        var url="http://192.168.1.14/youeryuan/index.php?g=";
        var type=$('#selector').val();

            if (username==""||username=="手机号/邮箱") {

                        $('#msg').html('<p style="color:red">请输入手机号码或邮箱!</P>')
                        return false;
            };

              if (loginpwd==""||loginpwd=="密码") {

                  $('#msg').html('<p style="color:red">请输入密码!</p>');
                  return false;
              };
        
              if (code==""||code=="验证码") {

                  $('#msg').html('<p style="color:red">请输入验证码!</p>');
                  return false;
              };

         
          if(!checkfield(username))
        {
            $('#msg').html('');
            $('#msg').html('<p style="color:red">请输入有效的手机号码或邮箱!</p>');    
            return false;
        }
        else
        {
            $('#msg').html('');
        }

        if (type==1) {

               var url1=url+'Teacher&m=Index&a=plogin&user='+username+'&loginpwd='+loginpwd+'&code='+code;    

        }
        else if(type==2) {

               var url1=url+'Parent&m=Index&a=plogin&user='+username+'&loginpwd='+loginpwd+'&code='+code;
        };

        $.ajax({
             type: "GET",  
             async: false,  
             url: url1,  
             dataType: "jsonp",  
             //jsonp: "callback",
             success: function(data){
                 if (data.data=='error') {

                       $('#msg').html('<p style="color:red">'+data.info+'</p>');    

                 }
                 else if(data.data=="succ")
                 {
                         if (type==1)
                         {                         
                                         //window.location.href="http://192.168.1.11/youeryuan/index.php?g=Teacher";
                                         //$('.log-box').html('您好,您已成功登录');      //登陆之后接着写 cookie         
                                         window.open(url+"Teacher");    
                         }
                         else
                         {                
                                         //$('.log-box').html('您好,您已成功登录');      //到时候换成其他的形式实现
                                          window.open(url+"Parent");
                                         //window.location.href="http://192.168.1.11/youeryuan/index.php?g=Parent";                              
                         }
                 }         
             },  
             error: function(){  
                 $('#msg').html('<p style="color:red">用户名或密码错误!</p>');
             }  
         });

     });       


     $("#loginbtn").click(function()
     {
          var url="http://192.168.1.14/youeryuan/index.php?g=";
            var type=$("#usertype").val();
            if(type=="1")
            {
                   window.open(url+"Teacher");
            }
            else 
            {               
                   window.open(url+"Parent");
            }      
     });



     $('#changeuser').click(function(){

                 $("#loginbox1").css("display","block");
                 $("#loginbox2").css("display","none");
     });



  });  
   function fastlogin()
   {  
                 $("#loginbox1").css("display","none");
                 $("#loginbox2").css("display","block");
   }


    function checkuserstatus()
     {
         url="http://192.168.1.14/youeryuan/index.php?g=Admin&m=Index&a=checkLogin";
         $.ajax({
             type: "GET",  
             async: false,  
             url:url,  
             dataType: "jsonp",  
             success: function(data){
                 if(data.status=="succ")//在线
                 {              
                        if (data.type=="3") {
                            $("#usermsg").html(data.name+"教师,您好。");
                            $('#usertype').val(1);
                        }
                        else if(data.type=='4')
                        {
                             $("#usermsg").html(data.name+"家长,您好。");
                             $('#usertype').val(2);
                        }
                       $("#loginbox1").css("display","none");
                       $("#loginbox2").css("display","block");
                       $("#fastloginspan").html('<a id="fastlogin" οnclick="fastlogin()" style="cursor:pointer">切换到快速登录模式</a>');                    
                 }
                 else if(data.status=='error')
                 {
                       //$('#msg').html('<p style="color:red">系统出现问题请稍后重试。</p>');
                 }       
             },  
             error: function(){  
                  //alert(1);
                 $('#msg').html('<p style="color:red">连接服务器失败,请重试。</p>');
             }  
         });
     }



     function checkfield(username)
     { 
           var myemailreg = /^([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$/;
           var myphonereg=/^(1[358]{1}[0-9]{9})$/i;
          if(!(myemailreg.test(username)||myphonereg.test(username)))
          {  
               return false;
          }
          else
          {
                 return true;
          }
     }  

</script> 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值