AJAX在GBK编码页面中传中文参数乱码的问题

时间:2023-06-29 14:17:32

---恢复内容开始---

页面编码是GBK的情况下传递中文有乱码,解决方法如下:

在ajax传递前用若是Array,JSON,等其它对象,可用JSON.stringfy字符串序列化后,赋值给ajax传递,

在后台获取后,对于未使用JSON.stringfy序列化的情况下,直接转码:将utf-8转成gbk编码的,再处理。

在后台进行转码。

mb_convert_encoding($brand_name, "GBK", "utf-8");

另一种解决方法

jQuery(form).ajaxSubmit({ 
url: "ajax.jsp?a=memberlogin", 
type: "post", 
dataType: "json", 
contentType: "application/x-www-form-urlencoded; charset=utf-8", 
success: showLoginResponse 
});