Example:
Rsajax.js:
Copy Code code 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 ($) {return Escape ($). Replace ((%u) (\w{4})/gi, "& #x $ 2; ")});
Newreslt=unescape (Result.replace (/& #x/g, '%u '). Replace (/;/g, ')); The Utf-8 and the Chinese characters turn, do not need
document.getElementById (' Waiting '). InnerHTML = ';
if (sys.ie) {
document.getElementById (' Showresults '). InnerHTML =gb2utf8 (Result); }
else{
document.getElementById (' Showresults '). InnerHTML =result;
}
} else {
Alert (' There is 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 Code code as follows:
<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<meta http-equiv= "Content-type" content= "text/html; charset=gb2312 "/>
<title></title>
<script type= "Text/javascript" language= "JavaScript" src= "Rsajax.js" ></script>
<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
We'll all come together, hey.