Example:
Rsajax. js:
Copy codeThe Code is as follows:
Var http_request = false;
Function makePOSTRequest (url, parameters ){
Http_request = false;
If (window. XMLHttpRequest ){
Http_request = new XMLHttpRequest ();
If (http_request.overrideMimeType ){
Http_request.overrideMimeType ('text/html ');
}
} Else if (window. ActiveXObject ){
Try {
Http_request = new ActiveXObject ("Msxml2.XMLHTTP ");
} Catch (e ){
Try {
Http_request = new ActiveXObject ("Microsoft. XMLHTTP ");
} Catch (e ){}
}
}
If (! Http_request ){
Alert ('cannot create XMLHTTP instance ');
Return false;
}
Http_request.onreadystatechange = alertContents;
Http_request.open ('post', url, true );
Http_request.setRequestHeader ("Content-type", "application/x-www-form-urlencoded ");
// Http_request.setRequestHeader ("Content-Type", "application/text/html; charset: UTF-8 ");
Http_request.setRequestHeader ("Content-length", parameters. length );
Http_request.setRequestHeader ("Connection", "close ");
If (! Sys. ie ){
Http_request.overrideMimeType ("text/html; charset = gb2312 ");
}
Http_request.send (parameters );
}
Function alertContents (){
If (http_request.readyState = 4 ){
If (http_request.status = 200 ){
If (Sys. ie ){
Result = http_request.responseBody;
}
Else
{
Result = http_request.responseText;
}
// Newresult = result. replace (/[^ \ u0000-\ u00FF]/g, function ($0) {return escape ($0 ). replace (/(% u) (\ w {4})/gi, "& # x $2 ;")});
// Newreslt = unescape (result. replace (/& # x/g, '% U '). replace (/;/g, ''); // convert UTF-8 and Chinese characters.
Document. getElementById ('waiting'). innerHTML = '';
If (Sys. ie ){
Document. getElementById ('showresults'). innerHTML = gb2utf8 (result );}
Else {
Document. getElementById ('showresults'). innerHTML = result;
}
} Else {
Alert ('There was a problem with the request .');
}
} Else {
Document. getElementById ('waiting'). innerHTML = ' ';}
}
Function get (obj ){
// Var poststr = "accounts =" + encodeURI (document. getElementById ("accounts"). value );
Makepostrequest('y.htm ','');
}
// Ie introduces a hybrid function, nndx
Function gb2utf8 (data ){
Var glbEncode = [];
Gb2utf8_data = data;
ExecScript ("gb2utf8_data = MidB (gb2utf8_data, 1)", "VBScript ");
Var t = escape (gb2utf8_data ). replace (/% u/g ,""). replace (/(. {2 })(. {2})/g, "%$ 2% $1 "). replace (/% ([A-Z].) % (. {2})/g, "@ $1 $2 ");
T = t. split ("@");
Var I = 0, j = t. length, k;
While (++ I <j ){
K = t [I]. substring (0, 4 );
If (! GlbEncode [k]) {
Gb2utf8_char = eval ("0x" + k );
ExecScript ("gb2utf8_char = Chr (gb2utf8_char)", "VBScript ");
GlbEncode [k] = escape (gb2utf8_char). substring (1, 6 );
}
T [I] = glbEncode [k] + t [I]. substring (4 );
}
Gb2utf8_data = gb2utf8_char = null;
Return unescape (t. join ("% "));
}
Var Sys = {};
Var ua = navigator. userAgent. toLowerCase ();
If (window. ActiveXObject)
Sys. ie = ua. match (/msie ([\ d.] +)/) [1]
Else if (document. getBoxObjectFor)
Sys. firefox = ua. match (/firefox \/([\ d.] +)/) [1]
Else if (window. MessageEvent &&! Document. getBoxObjectFor)
Sys. chrome = ua. match (/chrome \/([\ d.] +)/) [1]
Else if (window. opera)
Sys. opera = ua. match (/opera. ([\ d.] +)/) [1]
Else if (window. openDatabase)
Sys. safari = ua. match (/version \/([\ d.] +)/) [1];
Index. php
Copy codeThe Code is as follows:
<! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<Html xmlns = "http://www.w3.org/1999/xhtml">
<Head>
<Meta http-equiv = "content-type" content = "text/html; charset = gb2312"/>
<Title> </title>
<Script type = "text/javascript" language = "javascript" src = "rsajax. js"> </script>
<HEAD>
</Head>
<Body>
<Div align = "center">
<Input onclick = "javascript: get (document. getElementById ('acctform');" name = "acctform" id = "acctform" type = button>
<Div align = "center">
<Div id = "waiting"> </div>
<P>
<Div id = "showresults"> </div>
</Div>
<BR>
<Body>
Y.htm
Let's all join us, hey