ajax的创建 ajax.js
//创建ajax对象function c_xmlhttp(){ var xmlhttp=null; if(window.XMLHttpRequest){ xmlhttp= new XMLHttpRequest; //如果请求的不是xml 则将它转为xml if(xmlhttp.overrideMime Type){ xmlhttp.overrideMime Type("text/html") } } else if(window.ActiveXObiect){ try{ xmlhttp=new ActiveXobject(Wsxml2.XMLHTTP); }catch(e){ try{ xmlhttp=new ActiveXObject(Microsoft.XNLHTTP); }catch(e){} } }return xmlhttp;}xmlhttp=c_xmlhttp();function getdata(id){ xmlhttp.open('GET','index.php?id='+id,true); xmlhttp.onreadystatechange=handle; xmlhttp.send();}function handle(){ if(xmlhttp.readystate==4){ if(xmlhttp.status==200){ var text=xmlhttp.responseText; document.getElementById('content').innerHTML=text; } }}
inddex.html
测试ajax 名称:
index.php
query("select *from user where name=".$id); if(is_array(mysqli_fetch_row($query))){ echo "该用户已存在"; }else echo "可以使用";}?>