Get the App
SLTechnology News&Howtos  ›  Development  › 

AJAX's Chinese Encoding Transmission in GB2312 what is the correct method of AJAX special character coding

Shulou Source: shulou.com Published: 2022-06-03 07:48:06 11月15日 Update

This article shows you AJAX in GB2312 Chinese coding transmission AJAX special character coding correct method is how, the content is concise and easy to understand, absolutely can make your eyes bright, through the detailed introduction of this article, I hope you can get something.

Many may be distorted or unverified in the process of transfer, but not in real use, so they decided to try it in all directions, and their efforts have not been in vain. Although the final result is very simple, the process is really tiring for a new AJAX student.

You are welcome to communicate with posts on new ideas in the process of use. One thought + one thought can produce at least two ideas.

1. When sending GET:

Method 1: define the output code to the calling client with Response.charset= "GB2312" on the ASP server side

At this point, the client does not need to do any conversion. The following two files are:

1. Client JS

The copy code is as follows:

Var xmlHttp

Function createXML () {

If (window.ActiveXObject) {

XmlHttp=new ActiveXObject ("Microsoft.XMLHTTP")

} else if (window.XMLHttpRequest) {

XmlHttp=new XMLHttpRequest ()

}

}

Function startXml () {

CreateXML ()

XmlHttp.onreadystatechange = handleStateChange

Var url= "ajaxtext.asp?tm=1&cc" + Math.random ()

/ / var sendContents = 'theinput='+escape (theinput.value)

Var regcode= "2abc"

XmlHttp.open ("get", url,true)

/ / regcode= "regcode=" + regcode

/ / xmlHttp.setrequestheader ("content-length", regcode.length); / / add or not

/ / xmlHttp.setRequestHeader ("Cache-Control", "no-cache")

/ / xmlHttp.setRequestHeader ('Content-type','application/x-www-form-urlencoded'); / / No

/ / xmlHttp.send (null)

/ / xmlHttp.send ("regcode=" + escape (regcode))

XmlHttp.send (null)

}

Function handleStateChange () {

If (xmlHttp.readyState = = 4 & & xmlHttp.status==200) {

/ / var divid=document.getElementById ("results")

Retext=xmlHttp.responseText

Alert (retext)

/ / if (divid.hasChildNodes ()) {

/ / divid.removeChild (divid.childNodes [0])

/ /}

/ / var result=document.createTextNode (xmlHttp.responseText)

/ / divid.appendChild (result)

/ / document.getElementById ("results") [xss_clean] = xmlHttp.responseText

}

}

Server side:

The code is as follows:

Tags: Encoding character code service server special method client output string function format data content symbol article result UTF-8 Chinese Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Technology macOS Huawei MySQL Redmi