使用AJAX实现UTF8编码表单提交到GBK编码脚本无乱码的解决方法

1、表单项目1 GBK编码格式

用户采集单是GBK编码,通过GET/POST提交上来的数据也是GBK格式,无需做任何处理

测试源码

<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="GB2312">
</head>
<body>
<li><a href="http://www.cppcns.com/wangluo/asp/gbkForm.html" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >GBK同编码表单不乱码</a>
<li><a href="http://www.cppcns.com/wangluo/asp/utf8Form.html" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >UTF8表单修改前乱码</a>
<li><a href="http://www.cppcns.com/wangluo/asp/utf8FormRepair.html" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >UTF8表单修改为AJAX方案后不乱码</a>
<li><a href="http://www.cppcns.com/wangluo/asp/otherForm.html" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >其他GBK同编码表单不乱码</a>
<li><a href="http://www.miaoqiyuan.cn/p/utf8-submit-gbk-ajax-autocharset" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >测试程序说明</a></a>
<hr />
<h2>GET:</h2>
<form action="gbkSubmit.asp" method="GET" >
QQ:<input name="qq" value="http://www.cppcns.com/wangluo/asp/QQ" /><br />
姓名:<input name="name" value="http://www.cppcns.com/wangluo/asp/姓名"/><br />
地址:<input name="address" value="http://www.cppcns.com/wangluo/asp/地址地址地址"/><br />
<button type="submit">GBK表单提交到GBK脚本后不会乱码</button>
</form>
<h2>POST:</h2>
<form action="gbkSubmit.asp" method="POST" >
QQ:<input name="qq" value="http://www.cppcns.com/wangluo/asp/QQ" /><br />
姓名:<input name="name" value="http://www.cppcns.com/wangluo/asp/姓名"/><br />
地址:<input name="address" value="http://www.cppcns.com/wangluo/asp/地址地址地址"/><br />
<button type="submit">GBK表单提交到GBK脚本后不会乱码</button>
</form>
</body>
</html>

2、表单项目2 UTF8编码格式(可以在不同的域名下)

用户采集单是UTF8编码,通过GET/POST提交上来的数据也是UTF8格式,用表单项目1中的程序接收到的是乱码

测试代码(修改前,提交乱码):

<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF8">
</head>
<body>
<li><a href="http://www.cppcns.com/wangluo/asp/gbkForm.html" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >GBK同编码表单不乱码</a>
<li><a href="http://www.cppcns.com/wangluo/asp/utf8Form.html" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >UTF8表单修改前乱码</a>
<li><a href="http://www.cppcns.com/wangluo/asp/utf8FormRepair.html" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >UTF8表单修改为AJAX方案后不乱码</a>
<li><a href="http://www.cppcns.com/wangluo/asp/otherForm.html" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >其他GBK同编码表单不乱码</a>
<li><a href="http://www.miaoqiyuan.cn/p/utf8-submit-gbk-ajax-autocharset" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >测试程序说明</a></a>
<hr />
<h2>GET:</h2>
<form action="gbkSubmit.asp" method="GET" >
QQ:<input name="qq" value="http://www.cppcns.com/wangluo/asp/QQ" /><br />
姓名:<input name="name" value="http://www.cppcns.com/wangluo/asp/姓名"/><br />
地址:<input name="address" value="http://www.cppcns.com/wangluo/asp/地址地址地址"/><br />
<button type="submit">UTF8表单提交到GBK脚本后会乱码</button>
</form>
<h2>POST:</h2>
<form action="gbkSubmit.asp" method="POST" >
QQ:<input name="qq" value="http://www.cppcns.com/wangluo/asp/QQ" /><br />
姓名:<input name="name" value="http://www.cppcns.com/wangluo/asp/姓名"/><br />
地址:<input name="address" value="http://www.cppcns.com/wangluo/asp/地址地址地址"/><br />
<button type="submit">UTF8表单提交到GBK脚本后会乱码</button>
</form>
</body>
</html>

使用AJAX实现UTF8编码表单提交到GBK编码脚本无乱码的解决方法

扫一扫手机访问