Scene:
Using the Ajax method of jquery to submit the AJAX request, the code is as follows:
1$.ajax({
2 dataType : 'json'
3 ,type : 'POST'
4 ,url : 'http://localhost/test/test.do'
5 ,data : {id: 1, type: '商品'}
6 ,success : function(data){
7
8 }
9});
Problem:
When the back-end action program is submitted, the type being fetched is garbled
Workaround:
Method One: Use encodeURI two times before submitting the code, remember must be two times
1. Modify the following code
Data:{id:1, Type:encodeuri (encodeURI (' commodities '))}2. The string to be obtained is decode in the background action
1String type = request.getParameter("type");
2type = URLDecoder.decode(type, "UTF-8");
Method Two: Ajax configuration contenttype properties, plus Charset=utf-8
Add the following parameters to the Ajax method
1contentType: "application/x-www-form-urlencoded; Charset=utf-8 "Use other JS frame or XHR is similar, set header in ContentType can,
The key here is charset=utf-8, if there is no this, is not, the default jquery contenttype is not.
Plus, in jquery, the parameters have been processed once encodeuricomponent.
* Method Two do not need to decode in action, so it is recommended to use this method