AJAX在GBK编码页面中传中文参数乱码如何解决?

页面编码是GBK的情况下传递中文有乱码,这种情况有什么解决办法吗? 解决方案: 在ajax传递前用若是Array,JSON,等其它对象,可用JSON.stringfy字符串序列化后,赋值给ajax传递, 在后台获取后,对于未使用JSON.stringfy序列化的情况下,直接转码:将utf-8转成
页面编码是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 
});


 
本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

How to remove all roles and add one role on discord bot, and then remove the added role and restore previous roles(如何在discord bot上删除所有角色并添加一个角色,然后删除添加的角色并恢复以前的角色)
How can I check how many people have a role in a specific discord server?(如何查看有多少人在特定的不和谐服务器中担任角色?)
discord.js v12 check if channel exists(discord.js v12 检查频道是否存在)
My Discord.js bot is running (online and shows in console) but it won#39;t respond to commands(我的 Discord.js 机器人正在运行(在线并在控制台中显示)但它不会响应命令)
DiscordJS Bot - How to get the message immediately before another message in a channel?(DiscordJS Bot - 如何在频道中的另一条消息之前立即获取消息?)
Find the total of members online/offline Discord.js(在线/离线 Discord.js 查找成员总数)