form表单中填写中文后,传到后台为UTF-8代码,导致查询失败
原因:通过参数拼接的方式,导致会将中文转成UTF-8代码进行传输
解决方法:更改为post传参
原代码:
function _search(){ var roleInformation = $('#TOrhChkErrExamineTable'); roleInformation.datagrid({pageNumber:1,url:projectPath+'TOrhChkErrController/findAll.do?permissionCode=TORGCHKERREXAMINESEARCHCODE&'+$('#TOrhChkErrExamineForm').serialize(), onLoadError : function (data) { if(data.statusText=='Forbidden'){ Showbo.Msg.alert('抱歉,您的身份验证已过期!'); window.top.location.href=projectPath+"loginController/login.do"; } }}); $('#TOrhChkErrExamineTable').datagrid('clearSelections'); }
解决方案
1、创建一段js代码,以便于将form表单参数转换为json格式字符串
$.fn.serializeObject = function () { var o = {}; var a = this.serializeArray(); $.each(a, function () { if (o[this.name]) { if (!o[this.name].push) { o[this.name] = [o[this.name]]; } o[this.name].push(this.value || ''); } else { o[this.name] = this.value || ''; } }); return o; };
3、修改原方法中的传参方式。关键:在queryParams参数
function _search(){ var tOrhChkeeInformation = $('#TOrhChkErrExamineTable'); if($('#TOrhChkErrExamineForm').form('validate')){ tOrhChkeeInformation.datagrid({pageNumber:1, url:projectPath+'TOrhChkErrController/findAll.do?permissionCode=TORGCHKERREXAMINESEARCHCODE', queryParams: $('#TOrhChkErrExamineForm').serializeObject(), onLoadError : function (r) { if (r.statusText == 'Forbidden') { if (r.responseText != null&& r.responseText!="") { Showbo.Msg.alert(r.responseText); } else { Showbo.Msg.alert('抱歉,您的身份验证已过期!'); window.top.location.href = projectPath + "loginController/login.do"; } } }}); }else{ Showbo.Msg.alert('查询条件不能包含敏感字符'); } }