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:
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[i] + ""; } $("#accountDepartmentAdd").html(departmentSelector); });
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:
As 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");
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: 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[i] + "";
}
$("#accountDepartmentAdd").html(departmentSelector);
}
});
Recommended reading:
How to use PHP to prevent repeated submission of formsCodeIgniter framework database use case analysisThe 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!