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.