In addition to the blog without refreshing search and instant verification detection, and looked at the code, feel too troublesome, the XMLHttpRequest request package into a class inside, use it more convenient, do not remember so much code, what create XMLHttpRequest object or something, This part of the code is also relatively high reusability ~ has been packaged, at the end of the log download.
To see the effect of the point open the side of the log search, there is a no refresh search, it is, or in the reading log or in the book in the registration code where there is real-time detection, if you do not enter the verification code or the wrong authentication code, the input box will turn red ^_^
Class Name: Ajaxrequest
Create method: Var ajaxobj=new ajaxrequest, return False if creation fails
Properties: Method-Request methods, strings, post or get, default to post
URL-Request URL, string, default is NULL
Async-Asynchronous, true to asynchronous, false to synchronous, default to True
Content-the contents of the request, if this attribute is set by the request method for post, the default is null
Callback-callback function, that is, the function called when the response content is returned, the default is direct return, and the callback function has a parameter of XMLHttpRequest object, that is, when defining a callback function: function Mycallback (xmlobj)
Method: send-sending request, no parameters
An example:
Copy Code code as follows:
<script type= "Text/javascript" src= "Ajaxrequest.js" ></script>
<script type= "Text/javascript" >
var ajaxobj=new ajaxrequest; Creating Ajax Objects
Ajaxobj.method= "Get"; Set the request mode to get
Ajaxobj.url= "Default.asp"//URL is default.asp
Set callback function, output response content
Ajaxobj.callback=function (xmlobj) {
document.write (Xmlobj.responsetext);
}
Ajaxobj.send (); Send Request
Copy Code code as follows:
Ajax classes
function Ajaxrequest () {
var xmlobj = false;
var cbfunc,objself;
Objself=this;
try {xmlobj=new XMLHttpRequest;}
catch (e) {
try {xmlobj=new ActiveXObject ("MSXML2. XMLHTTP "); }
catch (E2) {
try {xmlobj=new ActiveXObject ("Microsoft.XMLHTTP");}
catch (E3) {Xmlobj=false}
}
}
if (!xmlobj) return false;
This.method= "POST";
This.url;
This.async=true;
This.content= "";
This.callback=function (cbobj) {return;}
This.send=function () {
if (!this.method| |! this.url| |! This.async) return false;
Xmlobj.open (This.method, This.url, This.async);
if (this.method== "POST") Xmlobj.setrequestheader ("Content-type", "application/x-www-form-urlencoded");
Xmlobj.onreadystatechange=function () {
if (xmlobj.readystate==4) {
if (xmlobj.status==200) {
Objself.callback (Xmlobj);
}
}
}
if (this.method== "POST") xmlobj.send (this.content);
else xmlobj.send (NULL);
}
}