jquery Ajax pass value, get way background Chinese garbled

Source: Internet
Author: User

jquery Ajax through the value, the background of Chinese garbled, after some groping found that the original client browser through get way to the project backstage, the encoding format is iso-8859-1, we need to go through the background transcoding to normal use. Here's how:

str = new String (str.getbytes ("iso-8859-1"), "Utf-8");

It is important to note that if you test locally, the default character encoding for background parsing is gb2312, no transcoding is required, so the code is certified as:

if (! Stringutil.getencoding (str). Equalsignorecase ("GB2312")) {

str = New String (Str.getbytes ("iso-8859-1"), "Utf-8");

}

The Stringutil class is as follows:

package com.hwcampus.common;public final class stringutil {public static  Boolean isempty (STRING STR)  {if  (Str != null && !str.trim (). IsEmpty ())  {//  if the string is not null and the value is not equal to the empty string after the whitespace is removed, the proof string has a substantial content return false;//not null}return true;// Null}private stringutil ()  {}/** *  Determine the encoding type of the string  *  @param  str *  @return  * author htc */public static string getencoding (STRING STR)  {           String encode =  "GB2312";           if (IsEmpty (str))  return  "";    try {             if  (Str.equals ( New string (Str.getbytes (encode),  encode))  {                   string s = encode;                  return s;               }          }  catch  (exception exception)  {           }          encode =  "ISO-8859-1";          try {              if  (Str.equals (new string (str.getbytes (encode),  encode))  {                   string  s1 = encode;                  return s1;              }           } catch  (Exception exception1)  {           }           encode =  "UTF-8";         try {              if  (Str.equals (new string ( Str.getbytes (encode),  encode))  {                   String s2 = encode;                  return s2;               }           } catch  (EXception exception2)  {          }           encode =  "GBK";          try {             if   (Str.equals (new string (str.getbytes (encode),  encode))  {                   String s3 =  encode;                  return s3;              }           } catch  (Exception exception3)  {           }          return  "";       }  } 


jquery Ajax pass value, get way background Chinese garbled

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.