Ajax transfer Data garbled problem the easiest solution! __ajax

Source: Internet
Author: User

It's been a headache. XMLHttpRequest When passing Chinese data when the garbled problem is generated.

Mostly on the internet, what utf-8, what gb2312, whatever.

I am tired of hearing, today an accidental idea, all of a sudden to solve the headache has been a problem, is the use of two functions.

Escape () and unescape ().

The server takes ASP as an example,

Response.Write Escape ("Chinese")

In this case, the client JS received is "%u4e2d%u6587" such a coded value,

This time, just use the JavaScript core language with the unescape () to decode it and restore it.

Unescape ("%u4e2d%u6587")

Very practical AH. And I tested a lot of text to encode and decode, the efficiency is very high AH.

Related Article

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.