AJAX乱码及错误解决方案是怎样的-创新互联
本篇文章给大家分享的是有关AJAX乱码及错误解决方案是怎样的,小编觉得挺实用的,因此分享给大家学习,希望大家阅读完这篇文章后可以有所收获,话不多说,跟着小编一起来看看吧。

成都创新互联从2013年开始,先为穆棱等服务建站,穆棱等地企业,进行企业商务咨询服务。为穆棱企业网站制作PC+手机+微官网三网同步一站式服务解决您的所有建站问题。
一类是出现乱码,另外一类是出现javascript系统错误:-1072896658的。提示在XX.innerHTML=xmlhttp.responseText;这行。
其实都是因为编码不统一引起的。解决方法就是加入指定字符编码指令。
一、什么是字符编码
定义见:http://zh.wikipedia.org/wiki/%E5%AD%97%E7%AC%A6%E7%BC%96%E7%A0%81。
通俗的讲:你看到的“我”是一张小图片,每个汉字都是,他对应一个编码4650,这些图片都存放在一个叫做字库的地方,你在字库中找到4650号图片,就是“我”了,其实字库就是windows的字体,宋体字库、雅黑字库等等等,一篇文章,你可以用宋体、仿宋体,不论用那种,“我”的对应的编码是不变的。你可以换字体,显示出来的“我”字体不同,但是还是一个“我”字。
二、问题的产生。
编码就有编码格式因此就产生了各种编码,汉字典型的有GB2312简体的,BIG5繁体的,Unicode繁简都有的。这里就产生问题了,在GB2312中4650是“我”,在Unicode中是6211。4650在Unicode中对应的是“䙐”。
因此,你在服务器的asp,jsp中用GB2312编码发送了“我”,到了浏览器,浏览器以为是Unicode,翻译出来就是“䙐”。这就是乱码了。
注意:本文中的Unicode仅以UTF-8为例。UTF-8定义传送门:http://zh.wikipedia.org/zh/UTF-8
三、解决思路。
当中还要注意一点:据不可靠消息JavaScript是用Unicode UTF-8作为内码的。
因此,如果使用Ajax,好呈现页面也指定编码为UTF-8,省的转换了。统一了编码,自然就没有了乱码。
四、具体方法。
对于服务端脚本,在脚本开头:
PHP:header('Content-Type:text/html;charset=UTF-8');
ASP:Response.Charset="UTF-8"
JSP:response.setHeader("Charset","UTF-8");
注意ASP,很多地方是Response.Charset("UTF-8"),这是不正确的,Charset是属性不是方法,误导了很多人。
对于HTML
复制代码 代码如下:
charset=编码名称。
对于
基本
文件
流程
错误
SQL
调试
- 请求信息 : 2026-05-24 04:14:08 HTTP/1.1 GET : /article/cdgpph.html
- 运行时间 : 2.2180s ( Load:0.0071s Init:1.5924s Exec:0.6086s Template:0.0099s )
- 吞吐率 : 0.45req/s
- 内存开销 : 2,224.08 kb
- 查询信息 : 12 queries 5 writes
- 文件加载 : 36
- 缓存信息 : 0 gets 0 writes
- 配置加载 : 130
- 会话信息 : SESSION_ID=oalrf2e5v5qtaautkqref0tng0
- /www/wwwroot/tsicrk.com/index.php ( 1.09 KB )
- /www/wwwroot/tsicrk.com/ThinkPHP/ThinkPHP.php ( 4.61 KB )
- /www/wwwroot/tsicrk.com/ThinkPHP/Library/Think/Think.class.php ( 12.26 KB )
- /www/wwwroot/tsicrk.com/ThinkPHP/Library/Think/Storage.class.php ( 1.37 KB )
- /www/wwwroot/tsicrk.com/ThinkPHP/Library/Think/Storage/Driver/File.class.php ( 3.52 KB )
- /www/wwwroot/tsicrk.com/ThinkPHP/Mode/common.php ( 2.82 KB )
- /www/wwwroot/tsicrk.com/ThinkPHP/Common/functions.php ( 53.56 KB )
- /www/wwwroot/tsicrk.com/ThinkPHP/Library/Think/Hook.class.php ( 4.01 KB )
- /www/wwwroot/tsicrk.com/ThinkPHP/Library/Think/App.class.php ( 13.49 KB )
- /www/wwwroot/tsicrk.com/ThinkPHP/Library/Think/Dispatcher.class.php ( 14.79 KB )
- /www/wwwroot/tsicrk.com/ThinkPHP/Library/Think/Route.class.php ( 13.36 KB )
- /www/wwwroot/tsicrk.com/ThinkPHP/Library/Think/Controller.class.php ( 11.23 KB )
- /www/wwwroot/tsicrk.com/ThinkPHP/Library/Think/View.class.php ( 7.59 KB )
- /www/wwwroot/tsicrk.com/ThinkPHP/Library/Behavior/BuildLiteBehavior.class.php ( 3.68 KB )
- /www/wwwroot/tsicrk.com/ThinkPHP/Library/Behavior/ParseTemplateBehavior.class.php ( 3.88 KB )
- /www/wwwroot/tsicrk.com/ThinkPHP/Library/Behavior/ContentReplaceBehavior.class.php ( 1.91 KB )
- /www/wwwroot/tsicrk.com/ThinkPHP/Conf/convention.php ( 11.15 KB )
- /www/wwwroot/tsicrk.com/App/Common/Conf/config.php ( 2.14 KB )
- /www/wwwroot/tsicrk.com/ThinkPHP/Lang/zh-cn.php ( 2.55 KB )
- /www/wwwroot/tsicrk.com/ThinkPHP/Conf/debug.php ( 1.49 KB )
- /www/wwwroot/tsicrk.com/App/Home/Conf/config.php ( 0.31 KB )
- /www/wwwroot/tsicrk.com/App/Home/Common/function.php ( 3.33 KB )
- /www/wwwroot/tsicrk.com/ThinkPHP/Library/Behavior/ReadHtmlCacheBehavior.class.php ( 5.62 KB )
- /www/wwwroot/tsicrk.com/App/Home/Controller/ArticleController.class.php ( 6.02 KB )
- /www/wwwroot/tsicrk.com/App/Home/Controller/CommController.class.php ( 1.60 KB )
- /www/wwwroot/tsicrk.com/ThinkPHP/Library/Think/Model.class.php ( 60.11 KB )
- /www/wwwroot/tsicrk.com/ThinkPHP/Library/Think/Db.class.php ( 32.43 KB )
- /www/wwwroot/tsicrk.com/ThinkPHP/Library/Think/Db/Driver/Pdo.class.php ( 16.74 KB )
- /www/wwwroot/tsicrk.com/ThinkPHP/Library/Think/Cache.class.php ( 3.83 KB )
- /www/wwwroot/tsicrk.com/ThinkPHP/Library/Think/Cache/Driver/File.class.php ( 5.87 KB )
- /www/wwwroot/tsicrk.com/ThinkPHP/Library/Think/Template.class.php ( 28.16 KB )
- /www/wwwroot/tsicrk.com/ThinkPHP/Library/Think/Template/TagLib/Cx.class.php ( 22.40 KB )
- /www/wwwroot/tsicrk.com/ThinkPHP/Library/Think/Template/TagLib.class.php ( 9.16 KB )
- /www/wwwroot/tsicrk.com/App/Runtime/Cache/Home/7540f392f42b28b481b30614275e4e55.php ( 17.71 KB )
- /www/wwwroot/tsicrk.com/ThinkPHP/Library/Behavior/WriteHtmlCacheBehavior.class.php ( 0.97 KB )
- /www/wwwroot/tsicrk.com/ThinkPHP/Library/Behavior/ShowPageTraceBehavior.class.php ( 5.24 KB )
- [ app_init ] --START--
- Run Behavior\BuildLiteBehavior [ RunTime:0.000006s ]
- [ app_init ] --END-- [ RunTime:0.000043s ]
- [ app_begin ] --START--
- Run Behavior\ReadHtmlCacheBehavior [ RunTime:0.000311s ]
- [ app_begin ] --END-- [ RunTime:0.000342s ]
- [ view_parse ] --START--
- [ template_filter ] --START--
- Run Behavior\ContentReplaceBehavior [ RunTime:0.000062s ]
- [ template_filter ] --END-- [ RunTime:0.000085s ]
- Run Behavior\ParseTemplateBehavior [ RunTime:0.006820s ]
- [ view_parse ] --END-- [ RunTime:0.006853s ]
- [ view_filter ] --START--
- Run Behavior\WriteHtmlCacheBehavior [ RunTime:0.000180s ]
- [ view_filter ] --END-- [ RunTime:0.000197s ]
- [ app_end ] --START--
- 1064:You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ') LIMIT 1' at line 1
[ SQL语句 ] : SELECT `id`,`pid`,`navname` FROM `cx_nav` WHERE ( id= ) LIMIT 1
- 1064:You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ') LIMIT 1' at line 1
[ SQL语句 ] : SELECT `id`,`navname` FROM `cx_nav` WHERE ( id= ) LIMIT 1
- 1064:You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ')' at line 1
[ SQL语句 ] : SELECT `id`,`navname` FROM `cx_nav` WHERE ( pid= )
- [8] Undefined index: pid /www/wwwroot/tsicrk.com/App/Home/Controller/ArticleController.class.php 第 47 行.
- [8] Undefined index: db_host /www/wwwroot/tsicrk.com/ThinkPHP/Library/Think/Db.class.php 第 120 行.
- [8] Undefined index: db_port /www/wwwroot/tsicrk.com/ThinkPHP/Library/Think/Db.class.php 第 121 行.
- [8] Undefined index: db_name /www/wwwroot/tsicrk.com/ThinkPHP/Library/Think/Db.class.php 第 122 行.

2.2180s
