The solution of Chinese garbled problem in Jquery.ajax URL

Source: Internet
Author: User
Tags character set

  This article is mainly on the jquery.ajax in the URL to pass the Chinese garbled problem solving method is introduced, the need for friends can come to the reference, I hope to be helpful to everyone

jquery   jquery Default contenttype:application/x-www-form-urlencoded    This is why 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.   Our UTF-8 can solve this problem.   ultimately refers to the need to modify the jquery code, the explicit declaration contenttype use Utf-8 character set, you can solve the problem of GB2312 Chinese delivery.   1. Modify the jquery code   simply modify the jquery code, plus 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 ESCAPC (str) And then decode it on the service side. How to transfer English, how to transfer Chinese.   Modify the 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:   Code is as follows: function Confirmcommit () {      var wlcompany = $ ("#wlCompany"). Val ()//Here is the Chinese   &N Bsp   var wlid = $ ("#wlId"). Val ();       var proposer = $ ("#proposer"). Val ();       if (confirm) ("Confirm the replacement?") {  $.ajax ({  type: ' POST ',   URL: ' ${pagecontext.request.contextpath}/returngoods/ Confrimexchangegoods.do ',   data: ' wlcompany= ' +wlcompany+ ' &wlid= ' +wlid+ ' &proposer= ' +proposer,//Direct transfer value   DataType: ' text ',   error:function () {      alert ("JQuery AJAX error!");       &N Bsp   Success:function (msg) {      alert (msg);       return;       if (msg = = ' Replacement success ', {   document.location= ' ${pagecontext.request.contextpath}/orderitem/queryproduceitem.do? Orderbustype= "+${orderbustype};      }  }  });       &NBSP}    }     3. Java code:   Code as follows: Public Actionforward confrimexchangegoods (actionmapping mapping,   actionform form, HttpServletRequest request,   HttpServletResponse response) throws Exception {  Log.info ("Confirm replacement Confrimexchangegoods start ...........   Response.setcharacterencodinG ("UTF-8"); Here to set the   String Wlcompany = Request.getparameter ("Wlcompany");   String wlid = Request.getparameter ("wlid");   String proposer = Request.getparameter ("proposer");     &NBSP ...}    
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.