How to quickly resolve jquery send request transfer Chinese parameter garbled

Source: Internet
Author: User
This time brings us how to quickly solve the jquery request transmission Chinese parameter garbled, quickly solve the jquery request transmission Chinese parameter garbled note what, the following is the actual case, to look at.

Recently in the need to do, related to cascading queries, you need to base on the contents of the drop-down box, to query out the Subordinate dropdown box list, because the cascade only two levels, and late to the table data is almost unchanged, so I designed the table is directly in Chinese.

The menu is as follows:

The code is as follows:

var url = "${basepath}/institutionconfig/getdepartmentbycenter.do?param=" + center;$.get (URL, function (data) {var list = Data.data; for (var i = 0; i < list.length; i++) {   Departmentselector + = "<option value= '" + list[i] + "'";   If (department && list[i] = = Department) {    departmentselector + = "selected= ' selected '";   }   Departmentselector + = ">" + list[i] + "</option>"; } $ ("#accountDepartmentAdd"). HTML (departmentselector);});

I used $.get(url, callback) to send the request to the background, because the parameters are sent directly by get, so the browser to the parameters with URL encoding encode, the following parameters are obtained:

Can see, Param received is garbled. So I went through the process of transcoding:

String center = new String (Param.getbytes ("iso8859-1"), "Utf-8");

This is the Chinese to receive.

But this practice in the test environment unexpectedly error, analysis of the next reason, found that the test environment received is the correct Chinese, transcoding is wrong. Therefore, the solution should be a request to change the page. Because the parameters that are caused by the Get method are encoded, the POST request submits the original data, instead of the posts requested:

var url = "${basepath}/institutionconfig/getdepartmentbycenter.do"; $.ajax ({  url:url,  data: {"param": Center },  DataType: "JSON",  type: "POST",  success:function (data) {   var list = Data.data;   for (var i = 0; i < list.length; i++) {    Departmentselector + = "<option value= '" + list[i] + "'";    If (department && list[i] = = Department) {     departmentselector + = "selected= ' selected '";    }    Departmentselector + = ">" + list[i] + "</option>";   }   $ ("#accountDepartmentAdd"). HTML (departmentselector);  } });

Believe that you have read the case of this article you have mastered the method, more exciting please pay attention to the PHP Chinese network other related articles!

Recommended reading:

How to prevent form recurrence by PHP implementation

CodeIgniter Framework database use case resolution

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.