WebService服务和ajax使用教程 [5]
看看如下效果:
登陆界面:

ajax需要的代码可能要稍微多一点:
function ajaxLogin(){
    var WebsUrl = 'http://s:81/userapp/login.asmx/Login?';
    if(!CheckLoadfocus(document.all.MyUserName)  )    {    
        alert('用户名不合法,请返回');
        return false;
    }else if (!CheckLoadfocus(document.all.MyUserName)  )    {    
        alert('密码不合法,请返回');
        return false;
    }
    var UrlStr = WebsUrl +'UserName='+document.all.MyUserName.value+'&UserPassword=
'+document.all.MyPassword.value;
    AjaxLogin(UrlStr);
    return false;
}
function CheckLoadfocus(thise){
    var sReg='([a-zA-Z0-9]+){3,}$';
    var reg = new RegExp(sReg,"i");
    try{
        if(!reg.test(thise.value)){
            thise.value ='admin';
            thise.style.background='#FFFFBF';
            thise.focus();
            thise.select();
            alert('提交不合法,请返回');
            return false;
        }
    thise.select();
    thise.style.background='#FFF';
    }catch(e){}
    return true;
}
function AjaxLogin(file){
  var xmlObj = null;
  if(window.XMLHttpRequest){
      xmlObj = new XMLHttpRequest();
  } else if(window.ActiveXObject){
      xmlObj = new ActiveXObject("Microsoft.XMLHTTP");
  } else {
      return;
  }
  xmlObj.onreadystatechange = function(){
    if(xmlObj.readyState == 4){
        var rstr;
        var mylevl = parseInt(xmlObj.responseXML.getElementsByTagName('int')[0].firstChild.data);
        if(mylevl>0){
            rstr=('登陆成功,权限是'+mylevl);
        }else{
            rstr=('登陆失败');
        }
        alert(rstr);
     }
    }
    xmlObj.open ('GET', file, true);
    xmlObj.send ('');
  }
 
                    
                     
                    
                 
                    
                
 
                
            
         
         浙公网安备 33010602011771号
浙公网安备 33010602011771号