ajax 乱码

function verify() { //解决中文乱麻问题的方法1,页面端发出的数据作一次encodeURI,服务器段使用new String(old.getBytes("iso8859-1"),"UTF-8"); //解决中文乱麻问题的方法2,页面端发出的数据作两次encodeURI,服务器段使用URLDecoder.decode(old,"UTF-8") var url = "AJAXServer?name=" + encodeURI(encodeURI($("#userName").val())); url = convertURL(url); $.get(url,null,function(data){ $("#result").html(data); }); } //给url地址增加时间戳,骗过浏览器,不读取缓存 function convertURL(url) { //获取时间戳 var timstamp = (new Date()).valueOf(); //将时间戳信息拼接到url上 //url = "AJAXServer" if (url.indexOf("?") >= 0) { url = url + "&t=" + timstamp; } else { url = url + "?t=" + timstamp; } return url; }

....................................................................

  httpServletResponse.setContentType("text/html;charset=utf-8");

String b = new String(dish_id.getBytes("ISO-8859-1"), "UTF-8");


String b = new String(dish_id.getBytes("ISO-8859-1"), "UTF-8");

具体:http://www.verydemo.com/demo_c107_i15852.html

相关推荐