PHP urlencode javascript decodeURI

WBOY
Release: 2016-06-23 14:36:23
Original
1111 people have browsed it

在ajax开发工程中不可避免的需要字符的转换操作,比如服务器的php urlencode编码之后就需要javascript解析。这时如果你用的是utf-8编码那么就不会遇到解析的问题,但是如果你用的是别的编码(gb2312 etc)直接用js decodeURI解析编码的话,就会报错。这是为什么呢?原来javascript解析的是utf-8编码,而这时传过来的是非utf-8(gb2312)编码。好了,找到原因就比较好解决了,先在服务器端把编码转换一下iconv('gb2312', 'utf-8', 'your string'),这时再用js解析试试 ^_^

 

把自己遇到的问题记录一下。

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!