easyui form表单.serialize()序列化后中文乱码问题原因及解决

来源:互联网 发布:ncut算法优劣 编辑:程序博客网 时间:2024/06/05 22:53
loginAndRegDialog=$('#loginAndRegDialog').dialog({
closable:false,
modal:true,
buttons:[{
text:"登录",
handler:function(){
var params=$('#LoginInputForm').serialize();
params = decodeURIComponent(params,true);
console.info(params);
$.ajax({
url:'userController.do?login',
data:$('#LoginInputForm').serialize(),
cache:false,
dataType:'json',
success:function(r){
$.messager.alert('My Title',r.msg,'error');
}
});

}

就是在调用序列化的时候,中文乱码,

原因:.serialize()自动调用了encodeURIComponent方法将数据编码了 
解决方法:调用decodeURIComponent(XXX,true);将数据解码 
例如: 
var params=$('#LoginInputForm').serialize();
params = decodeURIComponent(params,true);


还有一种办法是直接  --- console.info($('#name').val());
loginAndRegDialog=$('#loginAndRegDialog').dialog({
closable:false,
modal:true,
buttons:[{
text:"登录",
handler:function(){
var params=$('#LoginInputForm').serialize();
params = decodeURIComponent(params,true);
console.info($('#name').val());
$.ajax({
url:'userController.do?login',
data:$('#LoginInputForm').serialize(),
cache:false,
dataType:'json',
success:function(r){
$.messager.alert('My Title',r.msg,'error');
}
});

}



0 0
原创粉丝点击