2017-09-21 101 views
0

这是我的Ajax调用:字符解码失败。值损坏

function callServer() 
{ 
    alert('before : ' +uncompressed64Data.length); 
    var compressed = LZString.compressToUTF16(uncompressed64Data); 
    alert('after : ' +compressed.length); 

    debugger; 
    jQuery.ajax({ 
     url : "/RegisterServlet_2/servlet/Register", 
     type : "POST", 
     data: "img="+compressed, 
     cache : false, 
     async : false, 
     success : function() 
     { 

     }, 
     error : function() 
     { 
     } 
    }); 

} 

我收到以下错误,同时尝试接收它的错误:

字符解码失败。参数[img]的值是[????????????????????????? ä??à©?má¹?“’]已被忽略。请注意,由于解码失败,此处引用的名称和值可能会损坏。使用调试级别日志记录查看原始的未损坏的值。 HTML文件UTF8的

据透露, 1.I提到头 2.server.xml提到

URIEncoding="UTF-8" 

3.server侧提到,

request.setCharacterEncoding("utf-8"); 

请注意,我不想要任何编码,我只想获得我发送的数据。

在此先感谢。

回答

1

我觉得Content-Type引起的问题,默认jquery使用application/x-www-form-urlencoded; charset=UTF-8。尝试将其设置为text/plainmultipart/form-data。这里是documentation

+0

已经尝试过,它没有工作。 –

+0

也许会像UTF16一样压缩它的问题,但服务器需要按照您在标题中指定的方式使用UTF8。 – slesh

+0

multipart/form-data解决了这个问题!谢谢 –