如何在jquery.validate.js远程函数中用ajax请求解决中文乱码
how to sove chinese garbled with ajax request in jquery.validate.js remote function
示例:name=资源
rules: {
name: {
required: true,
remote: {
url: location.href.substring(0,location.href.lastIndexOf('/'))+"/resourceName/check/exists",
dataType: "text",
beforeSend: function(req) { req.setRequestHeader ("contentType", "text / html; charset = uft-8"); },
type: "GET"
}
},
url: {
required: true,
url: true
},
menu_id: "required"
}
在我的控制器中,我得到了这个名字,但它有点像"µæº",我该如何解决这个问题?
@RequestMapping(value = "/resourceName/check/exists", method = RequestMethod.GET)
public void isResourceNameExists(HttpServletResponse response,
@RequestParam(value = "name", required = false) String name)
throws IOException {
name = new String (name.getBytes("UTF-8"),"UTF-8");
response.setContentType ("text / text; charset = UTF-8");
response.setCharacterEncoding ("UTF-8");
response.getWriter().write(
String.valueOf(resourceService.findResourcesByName(name)
.isEmpty()));
}
我通过name = new String(name.getBytes("iso-8859-1"),"utf-8");
解决了这个问题
相关文章:
- ajax请求的顺序总是不同的
- 从ajax请求中获取javascript对象
- Ajax请求文档就绪会导致jquery加载缓慢
- MockJax没有在JavaScript应用程序中发送对我AJAX请求的响应
- 正在传递JSONP标头's数据参数到另一个文件中的AJAX请求
- JavaScript代码未正确检查ajax请求
- "日期“;AJAX请求返回的类型值未定义
- 在等待ajax请求时显示微调器并禁用页面
- 跨域ajax请求
- Ajax请求返回空的数据字符串,但首先得到了正确的数据
- Javascript-如何让脚本与Ajax请求的数据一起运行
- ajax请求成功,但可以'我看不到我的数据
- 如何将给定的curl命令复制为jquery ajax请求
- 为什么我能够从javascript控制台发送跨域ajax请求
- 一台特定计算机的Ajax请求数据未定义/失败
- 获取ajax请求的请求头
- 原型Ajax请求参数为嵌套json
- 可以't从AJAX请求中筛选数据
- jQuery Mobile Collapse上的AJAX请求
- 暂停函数执行流程,直到ajax请求完成