《php---ajax简单示例---jquery内部运行原理》---jquery只是就ajax的一些功能进行了封装
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><title>校验用户名</title><script type="text/javascript">//创建ajax引擎function getXmlHttpObject(){var xmlHttpRequest;//不同浏览器获取对象是不一样的if (window.ActiveXObject){//获取ie浏览器中的XmlHttpRequest对象xmlHttpRequest = new ActiveXObject("Microsoft.XMLHTTP");}else{//获取其他浏览器中的XmlHttpRequest对象xmlHttpRequest = new XMLHttpRequest();}return xmlHttpRequest;}var xmlHttpRequest;function checkName(){//获取XmlHttpRequest对象xmlHttpRequest = getXmlHttpObject();//指定请求的urlvar url = "/EPP/ajax/checkname.php";xmlHttpRequest.open("post",url,true);//true为是否异步加载xmlHttpRequest.setRequestHeader("Content-Type","application/x-www-form-urlencoded");//注册回调函数xmlHttpRequest.onreadystatechange = callBack;//需要向服务器发送的数据var data = "username=" +$("username").value;xmlHttpRequest.send(data);//发送数据}function callBack(){if (xmlHttpRequest.readyState == 4){//将接收的数据显示到页面上$('span').innerText = xmlHttpRequest.responseText;}}function $(id){return document.getElementById(id);}</script></head><body><form action="checkname.php" method="post">用户名:<input type="text" id="username" name="username"/><input type="button" onclick="checkName()" value="校验"/><span id="span" style="color : red;"></span></form></body></html>
<?php$username = $_POST['username'];if ($username != ""){if ($username == "fenghuo"){echo "用户名不可用";}else{echo "用户名可用";}}else{echo "请输入用户名";}?>