Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

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

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

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:

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report