Escape solution of Ajax Chinese garbled simple method

Source: Internet
Author: User

When using Ajax to develop a website, often have friends encounter garbled problems, and it is difficult to find a solution. In fact, to solve the problem of Ajax Chinese garbled is very simple.

1. Service-side program:

<%
 liststr="AJAX中文乱码的简单解决方法"
 sponse.write escape(liststr) '用escape编码
%>

2. Client JavaScript Program

function toserver(url)

{
var req = new XMLHttpRequest();
  if (req) {
   req.onreadystatechange = function() {
    if (req.readyState == 4 )
    {
     if(req.status == 200 || req.status == 304) {
       getstr=unescape(req.responseText)  '用unescape解码
             alert(getstr);
}
       else
     {return false;}
    }
   }
       req.open('GET',  url);
   req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8');
   req.send(null);
}

}

Through escape and unescape can solve Ajax Chinese garbled, extrapolate, this method can not only solve Ajax Chinese garbled, encounter other garbled problem can also use this method.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.