How to quickly solve jQuery's request to transmit garbled Chinese parameters

php中世界最好的语言
Release: 2023-03-28 09:36:02
Original
1709 people have browsed it

This time I will show you how to quickly solve jQuery's request to transmit garbled Chinese parameters, and how to quickly solve jQuery's request to transmit garbled Chinese parameters. . The demand I am currently working on involves cascading

Query

. It is necessary to query the list of lower-level drop-down boxes based on the content of the upper-level drop-down box, because the cascade only has two levels, and the table will be updated later. The data in will almost never change, so the table I designed stores Chinese directly. The menu is as follows:

How to quickly solve jQuerys request to transmit garbled Chinese parametersThe 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[i] + "";
 }
 $("#accountDepartmentAdd").html(departmentSelector);
});
Copy after login

I use

$.get(url, callback)

When sending a request to the background, since the parameters are sent directly in GET mode, the browser encodes the parameters with URL encoding, and the parameters obtained by the background are:

How to quickly solve jQuerys request to transmit garbled Chinese parametersAs you can see, param received garbled characters. So I performed further processing, that is, transcoding:

String center = new String(param.getBytes("iso8859-1"), "utf-8");
Copy after login

so that the received text is Chinese.

However, this approach actually reported an error in the test environment. After analyzing the reason, I found that the test environment received the correct Chinese, but it turned out to be wrong after transcoding. Therefore, the solution should be to change the page request. Because the parameters caused by the GET method are encoded, it is changed to

POST request

. The POST request will submit the original data:

I believe you have mastered the method after reading the case in this article, and more How exciting, please pay attention to other related articles on php Chinese website!

Recommended reading:

How to use PHP to prevent repeated submission of forms


CodeIgniter framework database use case analysis

The above is the detailed content of How to quickly solve jQuery's request to transmit garbled Chinese parameters. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!