About $ .ajax (use serialize ()) to submit the form appear in Chinese garbage problem

About $ .ajax (use serialize ()) to submit the form appear in Chinese garbage problem

Submitting the plurality of data, a value need not acquired a pass ajax, may be used as `` $ `(
" form "). The serialize (), which value is passed to form serialized Ajax () as a data parameter. Background object wrapper can be used directly.

jsp代码:  
$.ajax({
	type:"post",
	url:"org/add",
	data:$("#form-admin-add").serialize(),
	success:function(dat){
		if(data.result){
			alert(data.data);
		}
	}
})  
Controller代码:  
@ResponseBody
@RequestMapping("add")
public SysResult<String> add(SysOrg sysOrg){
	System.out.println(sysOrg);		
	System.out.println(sysOrg.getOrgName());
	int result = orgService.insertSelective(sysOrg);
	if(result > 0){
		return new SysResult<String>(true, "添加成功");
	}
	return new SysResult<String>(false, "添加失败");
}  

The reasons for the emergence of Chinese garbled form after a series of problems and solutions:
(1) Reason: After using ajax request when there is no request for setting type, the default mode uses a get request, and get request method to be used (String ) request.getParameter ( "username"), "utf-8"); for each individual transcoding Chinese garbage problem to solve
(2) solution: post request using a form submission is

Guess you like

Origin blog.csdn.net/qq_36510947/article/details/82872606