ajax的登录处理

来源:互联网 发布:qt 调用dotnet 编程 编辑:程序博客网 时间:2024/06/05 04:08
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<style type="text/css">

</style>
</head>
<body>
     
  用户名:<input type="text" name="username">
  密码: <input type="password" name="password">
  <button>提交</button>


  </div>
 
</body>
<script type="text/javascript">
    
  var userInp=document.getElementsByTagName('input')[0];
  var passInp=document.getElementsByTagName('input')[1];
  var btn=document.getElementsByTagName('button')[0];
  //绑定事件
  btn.onclick=function(){


  var ajax=new XMLHttpRequest();


      ajax.onload=function(){
             var data=ajax.responseText;
            alert(data);
      }
      ajax.open('POST','http://localhost/AJAX/php/log.php',true);


      ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded");


      ajax.send('username='+userInp.value+'&password='+passInp.value);


      }
</script>
</html>
原创粉丝点击