ajax中文乱码问题解决方案
2017-12-17 05:59
417 查看
在使用ajax发送请求给后台时,出现了中文乱码问题,搜索了很久之后得出最好的解决方法:encodeURIComponent,用法示例如下
$.ajax({
contentType: "application/x-www-form-urlencoded; charset=utf-8",
data:{
"keyword":encodeURIComponent(keyword),
//这里用encodeURIComponent来解决中文乱码问题,原因尚且不知,但是不添加的话会乱码
"page":searchPage
},
url:"something.do",
success:function(data){
console.log(songList);
}
});
encodeURIComponent方法将字符串转义,官方解释如下:
Encodes a Uniform Resource Identifier (URI) component by replacing each instance of certain characters by one, two, or three escape sequences representing the UTF-8 encoding of the character.
$.ajax({
contentType: "application/x-www-form-urlencoded; charset=utf-8",
data:{
"keyword":encodeURIComponent(keyword),
//这里用encodeURIComponent来解决中文乱码问题,原因尚且不知,但是不添加的话会乱码
"page":searchPage
},
url:"something.do",
success:function(data){
console.log(songList);
}
});
encodeURIComponent方法将字符串转义,官方解释如下:
Encodes a Uniform Resource Identifier (URI) component by replacing each instance of certain characters by one, two, or three escape sequences representing the UTF-8 encoding of the character.
相关文章推荐
- Ajax中文乱码问题解决方案
- Ajax中文乱码问题解决方案(servlet)
- SpringMVC Ajax请求时返回json中文字符串的乱码问题的解决方案
- Ajax中文乱码问题解决方案(servlet)
- ajax 文本框输入提示中文乱码问题解决方案
- Ajax中文乱码问题解决方案
- jQuery-Ajax提交数据中文乱码问题的解决方案
- ajax获取数据中文乱码问题最简单的完美解决方案
- ajax获取数据中文乱码问题最简单的完美解决方案
- Ajax Post请求中文乱码问题解决方案
- Ajax中的中文乱码问题的解决方案
- 关于Ajax请求中传输中文乱码问题的解决方案
- jquery1.4.2 ajax 中文乱码问题解决方案
- ajax中文乱码问题解决方案
- ajax获取数据中文乱码问题最简单的完美解决方案
- Ajax中的中文乱码问题的解决方案
- ajax中文乱码问题解决方案
- AJAX中文乱码问题解决方案
- jquery+jsp+servlet做$.ajax交互时出现中文乱码(字符集问题)的解决方案
- ajaxpro中文乱码问题解决方案