jquery post中文亂碼的解決辦法:1、前臺post請求的時候對傳送的資料進行【encodeURIComponent()】編碼;2、後臺用【UTF-8】轉譯。
該方法適用於所有品牌電腦
jquery post中文亂碼的解決辦法:
前臺post請求的時候對傳送的資料進行encodeURIComponent()
編碼
例如:
var transactType= $("#transactType").attr("value"); var content=encodeURIComponent($("#content").html()); var title=encodeURIComponent($("#title").val()); $.post( "${path}/transact!addTransact.action", {"content":content,"title":title}, function(data){ if(data=='1'){ alert("儲存成功!"); DG.cancel(); }else{ alert("儲存失敗!"); } } );
後臺:
用UTF-8
轉譯
transactType = URLDecoder.decode(getStringParameter("transactType"),"UTF-8"); content = URLDecoder.decode(getStringParameter("content"),"UTF-8"); title = URLDecoder.decode(getStringParameter("title"),"UTF-8");
即可解決jQuery post請求中文亂碼問題。
以上就是jquery post中文亂碼怎麼辦的詳細內容,更多請關注TW511.COM其它相關文章!