jquery post中文亂碼的解決辦法:1、前臺post請求的時候?qū)Πl(fā)送的數(shù)據(jù)進(jìn)行【encodeURIComponent()】編碼;2、后臺用【UTF-8】轉(zhuǎn)譯。
-
該方法適用于所有品牌電腦
jquery post中文亂碼的解決辦法:
前臺post請求的時候?qū)Πl(fā)送的數(shù)據(jù)進(jìn)行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
轉(zhuǎn)譯
transactType = URLDecoder.decode(getStringParameter("transactType"),"UTF-8"); content = URLDecoder.decode(getStringParameter("content"),"UTF-8"); title = URLDecoder.decode(getStringParameter("title"),"UTF-8");
即可解決jQuery post請求中文亂碼問題。
相關(guān)學(xué)習(xí)推薦:js視頻教程