我在ajax調用中發現波蘭字符問題。在下面的代碼中顯示的警報中,波蘭字符未能正確顯示。ajax調用中的波蘭字符編碼問題
$.ajax({
type: "GET",
url: "/module/getAllApps.htm",
encoding:"UTF-8",
contentType:"application/x-www-form-urlencoded; charset=UTF-8",
async: true,
success : function(response) {
if(response != null && response != "" && response!= '' && response != 'null'){
var appList = JSON.parse(response);
for(var i=0; i<appList.length; i++){
var module = appList[i];
alert(module.title);
}
}
},
error : function(e){
console.log('Error: ' + e);
}
});
下面是從控制器類方法
public void getAllApps(HttpServletRequest request, HttpServletResponse response){
Gson gson = new Gson();
List<Module> moduleList = moduleDao.getAllActiveModulesByDomain(domain.getDomainId());
try {
if(moduleList != null && moduleList.size()> 0){
response.getWriter().print(gson.toJson(moduleList));
} catch (Exception e) {
e.printStackTrace();
}
}
怎麼不來他們正確?請明確點。 – 2015-03-03 12:07:38