本文主要是介绍ajax_之get请求方式(ajax验证用户名),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
<!DOCTYPE html>
<html lang="en"><head><meta charset="utf-8"><script>function f1(){var username=document.getElementById('username').value;<span style="color:#ff0000;"> //对传递的特殊的特殊符号进行编码处理username=encodeURIComponent(username);</span>//1.创建ajax对象if(typeof ActiveXObject!="undefined"){var xhr=new ActiveXObject("Microsoft.XMLHTTP");//最原始方式var xhr=new ActiveXObject("Msxml2.XMLHTTP");//升级var xhr=new ActiveXObject("Msxml2.XMLHTTP.3.0");//升级var xhr=new ActiveXObject("Msxml2.XMLHTTP.6.0");//升级}else{var xhr=new XMLHttpRequest(); }//设置事件xhr.onreadystatechange=function(){if(xhr.readyState==4){alert(xhr.responseText);}}//连接服务器xhr.open(<span style="color:#ff0000;">'get','2.php?name='+username,true</span>);//异步传输:同一时间执行多个进程//发送请求xhr.send<span style="color:#ff0000;">(null</span>); }</script></head><body> //失去焦点触发用户名: <input type="text" <span style="color:#ff0000;">id="username"</span> name="username" <span style="color:#ff0000;">οnblur="f1()" </span>/><input type="password" id="pws" name="password"/></body>
</html>//2.php
<?phpprint_r($_GET);
?>
注意1.特殊符号的编码处理
2.open,url参数的添加
这篇关于ajax_之get请求方式(ajax验证用户名)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!