javascript 原生态ajax

function requestStatus(verifycode){
  var req=createRequest();
  req.open("POST","getVerifycode.do?isVerify=1&verifycode="+verifycode);
  req.onreadystatechange=function(){callback(req);}
  req.send(null);
 }
 function createRequest(){
  if(window.XMLHttpRequest){
   return new XMLHttpRequest();
  }else{
   try{
    return new ActiveXObject("Msxm12.XMLHTTP");
   }catch(e){
    return new ActiveXObject("Microsoft.XMLHTTP");
   }
  }
  return null;
 }
 //回调函数
 function callback(req){
  if(req.readyState==4){
   if(req.status==200){
    //获取返回值
    var data=req.responseText;
    if(data==1){
     loginSubmit();
    }else{
     alert('验证码输入有误');
     document.getElementById('verifycode').value='';
     getVerifycode();
    }
    return;
   }
  }
 }

 

你可能感兴趣的:(javascript 原生态ajax)