ASP Ajax No refresh save data program code

Source: Internet
Author: User

First create Access Object request

The code is as follows Copy Code

var request = false;

try{
Request = new XMLHttpRequest ();
}
catch (Trymicrosoft) {
try{
Request = new ActiveXObject ("Msxml2.xmlhttp");
}
catch (Othermicrosoft) {
try {
Request = new ActiveXObject ("Microsoft.XMLHTTP");
}
catch (Failed) {
Request = false;
}
}
}

if (!request)
Alert ("Error initializing xmlhttprequest!");

Re-define feedback receive function

function Updatepage () {
if (request.readystate = = 4) {
if (Request.status = = 200) {

alert (Request.responsetext);

} else{
Alert ("Status is" + Request.status);
}
}
}

In the place where the request is to be submitted, the following is the Get method

The code is as follows Copy Code

Request.open ("Get", "xxxx.asp?parm=yyyy", true);
Request.onreadystatechange = Updatepage;
Request.send (NULL);

The following opens the connection by post and can be up to 2K in size

The code is as follows Copy Code

Request.open ("POST", url, True);
Request.setrequestheader ("Content-type", "application/x-www-form-urlencoded");
Request.onreadystatechange = Updatepage;
Request.send ("parm1=....&parm2= ...");

Finally, if the parameter contains special characters, first use the Escape () function code, the server end with unescape decoding. Both JavaScript and ASP support both functions.

Summary: No, you are asp,php, asp.net,jsp, etc. and Ajax when used in conjunction with the server script that is the same as other server script processing data, but our Ajax part is a bit different, but the overall is no different.

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.