How to encode the GB2312 website so that the data received by AJAX can be displayed in Chinese
This article is about how the website coded as GB2312 allows the data received by AJAX to display content that supports Chinese. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.
The code is as follows:
Var xmlHttp
Var BrowerType= "ie"
Function createXML () {
Try {
XmlHttp = new ActiveXObject ("Msxml2.XMLHTTP")
} catch (e) {
Try {
XmlHttp = new ActiveXObject ("Microsoft.XMLHTTP")
} catch (e2) {
XmlHttp = false
}
}
If (! xmlHttp & & typeof XMLHttpRequest! = 'undefined') {
XmlHttp = new XMLHttpRequest ()
BrowerType = "ff"; / / used to record whether Firefox is used for the following processing to receive Chinese data for analysis.
}
}
Function querytelcode (citys) {
CreateXML ()
ShowState=document.getElementById ("showtelcode")
XmlHttp.onreadystatechange = function () {
If (xmlHttp.readyState = = 2) {
ShowState [XSS _ clean] ='
'
} else if (xmlHttp.readyState = = 4 & & xmlHttp.status = = 200) {
If (BrowerType== "ff") {
GetLastCode=xmlHttp.responseText;//FireFox
} else {
GetLastCode=gb2utf8 (xmlHttp.responseBody)
}
ShowStat [XSS _ clean] = getLastCode
}
}
Var url='myorderAjax.asp?oid=&cityname='+citys
XmlHttp.open ("GET", url,true)
If (BrowerType== "ff") {
XmlHttp.overrideMimeType ("text/html;charset=gb2312"); / / sets the data to be identified by gb2312 encoding, which is supported only by FF. IE can't.
}
XmlHttp.send (null)
}
Function gb2utf8 (data) {
Var glbEncode = []
Gb2utf8_data = data
ExecScript ("gb2utf8_data = MidB (gb2utf8_data, 1)", "VBScript")
Var t=escape (gb2utf8_data) .replace (/% ucharg, "). Replace (/ (. {2}) (. {2}) / g,"% $2% replace 1 "). Replace (/% ([Amurz].)% (. {2}) / g," @ $1 $2 ")
T=t.split ("@")
Var iMago, jend.futhje, k
While (+ + I