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