<script>
var xmlhttp;
function loadXMLDoc(url,cfunc)
{
if (window.XMLHttpRequest)
{// IE7+, Firefox, Chrome, Opera, Safari 代码
xmlhttp=new XMLHttpRequest();
}
else
{// IE6, IE5 代码
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=cfunc;
xmlhttp.open("GET",url,true);
xmlhttp.send();
}
function myFunction1(str)
{
loadXMLDoc("http://localhost/Project1/Select.php?name="+str,function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
if(xmlhttp.responseText=="yes"){
document.getElementById("name1").innerHTML = "用户名已存在";}
else{
document.getElementById("name1").innerHTML = "用户名正确";}
}
});
}
1. Create XMLHttpRequest object
All modern browsers (IE7 +, Firefox, Chrome, Safari and Opera) are built-in XMLHttpRequest object.
Create XMLHttpRequest object syntax:
Older versions of Internet Explorer (IE5 and IE6) using ActiveX objects:
In order to cope with all modern browsers, including IE5 and IE6, please check whether the browser supports the XMLHttpRequest object. If supported, XMLHttpRequest objects are created. If not, then create ActiveXObjec
Second transmission request to the server
To send a request to the server, we use the XMLHttpRequest object's open () and send () method:
xmlhttp.send();
method | description |
---|---|
open(method,url,async) | Type specifies the request, URL, and whether asynchronous request processing.
|
send(string) | Sends a request to the server.
|