使用getJSON想後臺提交數據是中文亂碼,即使吧tomcat的server.xml中配置了URIEncoding="UTF-8",中文亂碼問題依舊存在。ajax
存在緣由是引文getJSON中不能設置編碼格式致使的,因此換成ajax而後在參數中設置編碼格式便可。實例以下:json
$.getJSON("?beanName=CityData",{"province":ui.item.value},request1,function(data1,status1,xhr1){ response1($.grep(data1,function(item){ if(item.indexOf(request1.term)!=-1)return item; }));
換成以下代碼:tomcat
$.ajax({ url:"?beanName=CityData", data:{"province":ui.item.value}, type:"post", contentType: "application/x-www-form-urlencoded", dataType:"json", charset:"utf-8", success:function(data1){ response1($.grep(data1,function(item){ //console.log(item); if(item.indexOf(request1.term)!=-1)return item; })); } });