The solution of Chinese garbled problem in Jquery.ajax URL _jquery

Source: Internet
Author: User


jquery default contenttype:application/x-www-form-urlencoded

This is the reason jquery is garbled, when the character set is not specified, is the use of iso-8859-1

Iso8859-1, usually called Latin-1. Latin-1 includes additional characters that are indispensable for writing all Western European languages.

jquery Ajax does not take into account the internationalization of the problem, the use of the European character set, so it caused the transfer of Chinese garbled problem.

And our UTF-8 can solve this problem.

Finally refers to the need to modify the jquery code, the explicit declaration contenttype use the Utf-8 character set, can solve the problem of GB2312 Chinese delivery.

1. Modify the jquery code

Simply modify the jquery code, plus the Charset=utf-8, so that you don't need to change what web.config or what is encoded in the page, and you don't need to use ESCAPC (str) to decode the server. How to transfer English, how to transfer Chinese.

To modify a used jquery file: jquery-1.4.4.min.js

ajaxsettings: {url:location.href,global:true,type: "Get", ContentType: "Application/x-www-form-urlencoded; charset=utf-8 ", Processdata:true,async:true,xhr:function () {return new e.xmlhttprequest}

2. JS Code:

Copy Code code as follows:

function Confirmcommit () {

var wlcompany = $ ("#wlCompany"). Val ()//This contains Chinese

var wlid = $ ("#wlId"). Val ();

var proposer = $ ("#proposer"). Val ();

if (Confirm ("Confirm to replace it")) {

$.ajax ({

Type: ' POST ',

URL: ' ${pagecontext.request.contextpath}/returngoods/ ',

Data: ' wlcompany= ' +wlcompany+ ' &wlid= ' +wlid+ ' &proposer= ' +proposer,//Direct transfer value

DataType: ' Text ',

Error:function () {

Alert ("JQuery AJAX error!");


Success:function (msg) {

Alert (msg);


if (msg== ' replacement success ') {

document.location= "${pagecontext.request.contextpath}/orderitem/" +${ Orderbustype};






3. Java code:
Copy Code code as follows:

Public Actionforward confrimexchangegoods (actionmapping mapping,

Actionform form, HttpServletRequest request,

HttpServletResponse response) throws Exception { ("Confirmation of the replacement confrimexchangegoods start ..."), and the

Response.setcharacterencoding ("UTF-8"); Here to set the

String Wlcompany = Request.getparameter ("Wlcompany");

String wlid = Request.getparameter ("wlid");

String proposer = Request.getparameter ("proposer");

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