Ajax Chinese garbled

Source: Internet
Author: User
Js Code:
Function doFind (default_value ){
Var q_bureau_name = document. forms [0]. q_bureau_name.value;
Var defpars = '';
If (default_value! = Null ){
Defpars = '& default_value =' + default_value;
}
Var url = 'mermeroperaction. do ';
Var pars = 'Action = getbureaulist & sname = customerTel. TEL_BUREAU & q_bureau_name = '+ encodeURI (q_bureau_name) + defpars; // encodeURI encodes text strings into a valid Uniform Resource Identifier (URI) twice ).
Var my = new Ajax. Request (url, {method: 'post', parameters: pars, onComplete: show });
}
Function show (originalRequest)
{
Var BUREAUSPAN = document. getElementById ("BUREAUSPAN ");
BUREAUSPAN. innerHTML = originalRequest. responseText;
}
Java code
String q_bureau_name = Util. filter (request. getParameter ("q_bureau_name "));
Q_bureau_name = java.net. URLDecoder. decode (q_bureau_name, "UTF-8 ");
// Ajax submits data (post) in UTF-8 format by default, using the escape () or encodeURI () method provided by javascript. use java.net. URLDecoder. decode (value, "UTF-8") method for decoding.

Js knowledge:
Escape Method

PairStringObject encoding so that they can be read on all computers,

escape(charString)

RequiredCharstringThe parameter is arbitrary to be encoded.StringObject or text.

Description

EscapeMethod returnsCharstringThe string value of the content (in Unicode format ). All spaces, punctuation marks, accents, and other non-ASCII characters are used%XxEncoding, whereXxEqual to the hexadecimal number of the character. For example, "% 20" is returned by a space ".

If the character value is greater than 255% UXxxxFormat storage.

Note: EscapeThe method cannot be used to encode the Uniform Resource Identifier (URI. Encoding should be usedEncodeURIAndEncodeURIComponentMethod.

EncodeURI Method

Encodes a text string into a valid Uniform Resource Identifier (URI ).

encodeURI(URIString)

RequiredURIStringThe parameter represents an encoded URI.

Description

EncodeURIMethod returns an encoded URI. If you pass the encoding resultDecodeURI, Then the initial string is returned.EncodeURIThe method does not encode the following characters: ":", "/", ";", and "? ". Please useEncodeURIComponentTo encode these characters.

EncodeURIComponent Method

Encodes a text string into a valid component of a uniform resource identifier (URI.

encodeURIComponent(encodedURIString)

RequiredEncodedURIStringThe parameter represents an encoded URI component.

Description

EncodeURIComponentReturns an encoded URI. If you pass the encoding resultDecodeURIComponent, Then the initial string is returned. BecauseEncodeURIComponentMethod to encode all characters. Note that if the string represents a path, for example/Folder1/folder2/default.htmlThe slash is also encoded. In this way, when the encoding result is sent to the web server as a request, it will be invalid. If the string contains more than one URI component, useEncodeURIMethod.

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.