Some simple basics, some small details, may determine the success or failure of a function or even a software.
A few days ago to do a small function, user registration using AJAX to verify that the user name has been registered. Because in this small project, only Ajax is used here, so it is not intended to use the previously used prototype. Start with the Get method to submit the data, and then think about it, or to post it, no other reason, because the prototype by default is the Post method, so I feel that post looks pleasing to the eye. The written JavaScript code is as follows:
Javascript
var ajax=function (option) {
var request;
var createrquest=function () {
var HttpRequest;
try{
Httprequest=new ActiveXObject ("msxml2.xmlhttp");
}catch (e) {
try{
Httprequest=new ActiveXObject ("Microsoft.XMLHTTP");
}catch (E1) {
Httprequest=new XMLHttpRequest ();
}
}
return HttpRequest;
}
var sendrequest=function () {
Request=createrquest ();
Request.open ("post", option.) Url,true);
Request.onreadystatechange=responserequest;
Request.send (option. Param);
}
var responserequest=function () {
if (request.readystate==4) {
if (request.status==200) {
Option. Success (Request);
}
else{
Option. Failure (request);
}
}
}
SendRequest ();
}
var onblur=function (EL)
{
var option={
URL: "Handler.ashx",
Param: "TEXT=ABV",
Success:function (Request) {
alert (Request.responsetext);
},
Failure:function (Request) {
Alert (false);
}
};
New Ajax (option);
}