javascript里ajax的XMLHttpRequest.responseText,中文有乱码

JavaScript013

javascript里ajax的XMLHttpRequest.responseText,中文有乱码,第1张

这个我遇到过,你在javascript页面要用两次encodeURI(name)函数,记住一定是2次

var name = “中文”

name=encodeURI(name)

name=encodeURI(name)

在服务器处理页面用

String name=request.getParameter("name")

String gbk_name=URLDecoder.decode(name,"utf-8")//中文转成utf-8

gbk_name 就是中文的了。

你的js文件和html文件的%文件编码%不一制就会这样。

把你的文件另存为【或通过其它方法修改文件编码】 都改成utf-8或gb2312就好了。

js中要注意的就是 html,js, request[请求]编码都要一致。

你好,乱码肯定还是编码的问题。html代码编码和文件的编码必须一致。

GB2312:

<meta

http-equiv="Content-Type"

content="text/html

charset=gb2312">

文件另存为编码选ANSI

urf-8:

<meta

http-equiv="Content-Type"

content="text/html

charset=utf-8">