The use of the Ajax Post method

Source: Internet
Author: User

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);
}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.