前臺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請求中文亂碼問題。
例如:
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請求中文亂碼問題。