Home  >  Article  >  Web Front-end  >  Solution to garbled ajax request (Chinese garbled code)_javascript skills

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

WBOY
WBOYOriginal
2016-05-16 16:52:521186browse

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.
Statement:
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