Home > Web Front-end > JS Tutorial > body text

Solution to garbled ajax request (Chinese garbled code)_javascript skills

WBOY
Release: 2016-05-16 16:52:52
Original
1135 people have browsed it

I encountered a problem today, regarding the problem of garbled characters when transmitting Chinese in an ajax request.

The following code:

Copy the code The code is as follows:

function UpdateFolderInfoByCustId(folderId, folderName , custId) {
$.ajax({
) type: "Post",
contentType: "application/x-www-form-urlencoded; charset=utf-8",
url: " http://localhost/CRM/Ashx/HandKBSucessCustomer.ashx?Method=UpdateCustomerByCustId&folderId="
folderId "&folderName=" encodeURI(encodeURI(folderName)) "&custId=" custId,
success: function (msg) {
                                                            ;


If you just pass "&foderName=" folderName in the above code, the Chinese characters will be garbled. If converted twice through encodeURL, the Chinese character encoding will become similar to

The format of “test믕”. After converting to this format, transcode when retrieving, as shown below:

Copy code


The code is as follows:

public void UpdateCustomerByCustId () string folderName2 = Convert.ToString(System.Web.HttpUtility.UrlDecode(folderName)); int custId = Convert.ToInt32(Request["custId"]); bool res = false; try                                                                                                                                                                                                                                                                                                                                         (res);
}
}
}



After this conversion, the transmitted Chinese characters can be obtained.
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!