jquery garbled and ContentType property setup problem solution _jquery

Source: Internet
Author: User
Today's idle boredom, the previous legacy of the problem to solve, such as a headache jquery garbled problem. In fact, this article has a lot of, but a comprehensive solution to a variety of problems, today summed up, convenient for everyone.

The reason is simple .: In fact, his Chinese garbled is because ContentType did not specify the encoding, for different jquery version of this place has different settings, take what I encountered, jquery-1.6.1 and jquery-1.8.3 have different definitions.

Solutions: In the jquery-1.6.1 file, search for ' contentType ' and add it after application/x-www-form-urlencoded; Charset=utf-8 eventually turned into contenttype: "application/x-www-form-urlencoded; Charset=utf-8 "can be.
This way through the Post method will appear garbled problem can be solved perfectly.

If there are garbled phenomenon, can only say that you receive the page coding also have problems, this is because the asynchronous object XMLHttpRequest in the processing of returned ResponseText, is the UTF-8 encoding to decode. So the Post method, you have to save this page, the page file encoding to UTF-8 (please remember).

Before the modification, the entire from form data is garbled state, for this situation, we can easily solve the above method.

The following is a summary of some of the special issues that come from the network:
JQuery Ajax submission of Chinese garbled solution 2
Use jquery before the time has not found that the use of Ajax submission will appear garbled, I guess it is because of the coding reasons

There are several possible reasons for this
1.HTML coding is not uniform: the page is GB2312, as if jquery doesn't support it very well. I have always used UTF-8, have not found;
2. File encoding, this is not good to see on the surface, the simplified Chinese version of the operating system in the text format of the file default is GB2312, it is recommended to replace the file UTF-8 format
The simplest solution, the submission of Chinese text with JS escape processing, it will not appear garbled.
Such as:
Copy Code code as follows:

Save data
$.ajax ({
URL: "/guide/savecomments.aspx",
Type: "POST",
DataType: "JSON",
Data: "Action=savecomment&commnickname=" +escape (Commnickname.val ()) + "&commcontent=" +escape ( Commcontent.val ()) + "&guideid=" + guideid.val () + "&scorelogtype=<%=scorelogtype%>",
Success:function (Results) {
alert (results.message);

-------------------------------------------------------------------------------
The solution to use JS encoding function encodeURIComponent (string) processing, the Chinese "Wang" code into "%e7%8e%8b%e6%99%93%e6%98%8e", OK.
By the way, my tomcat under the Uriencoding=utf-8
-------------------------------------------------------------------------------
Today in the use of jquery to detect the user name, the English and the number of user name detection is correct, but the Chinese time, detection error, after the online query for some time, finally found the reason, is garbled problem, the solution:
1, as long as in the AJAX data submitted, if the page encoding is not utf-8, should be submitted to the data coding, JS encoding function for escape ()
2, after the server-side page to receive data decoding, and then the data related to the processing and then coding
3, return to the client and then decode
4, if not submit data, but directly from the server to obtain data, that directly in the server page set response.charset= "gb2312" can be, no more coding and decoding
In VBScript correspond to the Escape () and unescape () function program code of JS respectively
-------------------------------------------------------------------------------
resolved through the following processing methods
When passing parameters, the parameters are encoded pricename= "encodeURI (pricename)", or encodeuricomponent () can be used.
No additional processing is required on the server side: String pricename = Request.getparameter ("Pricename");

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.