jQuery ajax 提交表单中文乱码的问题

jQuery ajax 提交表单中文乱码的问题                          
解决方法:                                                       
前端:js中                                                       
原因:.serialize()自动调用了encodeURIComponent方法将数据编码了           
解决方法:调用decodeURIComponent(XXX,true);将数据解码               
var params = $('#form_address_form').serialize();                           
    params = encodeURI(params);                                       
    $.ajax({                                                                
        type : 'POST',                                              
        url : 'saveAddress.action',                                       
        data : params,                                               
        //contentType: "application/x-www-form-urlencoded; charset=utf-8",    
        success : function(response) {                                  
            if(response=='success'){                                   
                var url = 'getShoperInfo.action';                      
                $('#addressList').window('refresh', url);                  
            }                                                 
        }                                                    
    });                                                         
                                                             
后台java中:                                                     
每个中文字段都要加上                                           
String name = getHttpServletRequest().getParameter("name");          
name = URLDecoder.decode(name, "UTF-8");

你可能感兴趣的:(jQuery)