JQuery中使用Ajax传中文参数乱码解决方案(javaweb开发)

来源:互联网 发布:一知f君张碧晨三部 编辑:程序博客网 时间:2024/05/21 13:56

JQuery中使用Ajax传中文参数乱码解决方案(javaweb开发)

解决方法

$.ajax({ 

var url = "这里填写你要传的参数,格式: a=1&b=2";
//用get方式提交不然中文会乱码
type: "get", 
url: "/login.do",
data: url,
dataType:"json",
success: function(json){

});

1.用get方式提交不要用post方式提交,  

2.后台取值的话需要将字符串转码 不然还是会出现乱码。

String username = new String(request.getParameter("username").getBytes("ISO-8859-1"),"GBK");

 这样System.out.println(username);出来的中文就不是乱码了!


0 0