繁华开满天机
123456789101112131415161718192021222324252627282930313233<script type="text/javascript"> //请求函数 function f1(){ console.log('start'); //1.创建AJAX对象 var ajax = new XMLHttpRequest(); //4.给AJAX设置事件(这里最多感知4[1-4]个状态) ajax.onreadystatechange = function(){ //5.获取响应 //responseText 以字符串的形式接收服务器返回的信息 //console.log(ajax.readyState); if(ajax.readyState == 4 && ajax.status == 200){ var msg = ajax.responseText; console.log(msg); //alert(msg); var divtag = document.getElementById('result'); divtag.innerHTML = msg; } } //2.创建http请求,并设置请求地址 var username = document.getElementsByTagName('input')[0].value; var email = document.getElementsByTagName('input')[1].value; username = encodeURIComponent(username); //对输入的特殊符号(&,=等)进行编码 email = encodeURIComponent(email); ajax.open('get','response.php?username='+username+'&email='+email); //3.发送请求(get--null post--数据) ajax.send(null); } </script>