ajax js used in the

<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:

variable=new XMLHttpRequest();

Older versions of Internet Explorer (IE5 and IE6) using ActiveX objects:

variable=new ActiveXObject("Microsoft.XMLHTTP");

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.open("GET","ajax_info.txt",true);
xmlhttp.send();

 

method description
open(method,url,async)

Type specifies the request, URL, and whether asynchronous request processing.

  • Method : type of the request; the GET or POST
  • url : location of the file on the server
  • the async : to true (asynchronous) or false (synchronous)
send(string)

Sends a request to the server.

  • String : POST requests only

Guess you like

Origin www.cnblogs.com/insist-bin/p/11025292.html