The XMLHTTP object created using JavaScript submits a request to the ASP page, and the returned value may be garbled.
One solution is simple: Add response. charset = "gb2312" before the ASP return value ".
Complete Code As follows:
Html
<Script language = "JavaScript">
Function createxmlhttp ()
{
VaR try = {
These: function ()
{
VaR returnvalue;
For (VAR I = 0; I <arguments. length; I ++)
{
VaR Lambda = arguments [I];
Try
{
Returnvalue = Lambda ();
Break;
} Catch (e ){}
}
Return returnvalue;
}
}
VaR XMLHTTP = Try. These
(
Function () {return New activexobject ('msxml2. xmlhttp ')},
Function () {return New activexobject ('Microsoft. xmlhttp ')},
Function () {return New XMLHttpRequest ()}
) | False;
Return XMLHTTP;
}
VaR XMLHTTP = createxmlhttp ();
XMLHTTP. onreadystatechange = function (){
If (XMLHTTP. readystate = 4)
{
If (XMLHTTP. Status = 200)
{
Document. getelementbyid ("MSG"). innerhtml = XMLHTTP. responsetext;
}
}
}
XMLHTTP. Open ("Post", "responsetest. asp", true );
XMLHTTP. setRequestHeader ('content-type', 'application/X-WWW-form-urlencoded ');
XMLHTTP. Send (true );
</SCRIPT>
<Table border = "0" cellspacing = "0" cellpadding = "0" width = "500" align = "center">
<Tr align = Center Height = "8">
<TD id = "MSG"> </TD>
</Tr>
<Tr align = center>
<TD> test </TD>
</Tr>
</Table>
responsetest. ASP
<%
response. charset = "gb2312"
response. write (" result completed ")
response. end ()
%>