Home >Backend Development >PHP Tutorial >PHP urlencode javascript decodeURI

PHP urlencode javascript decodeURI

WBOY
WBOYOriginal
2016-06-23 14:36:231176browse

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

 

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

Statement:
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
Previous article:PHP ob_start()与ob_gzhandler()Next article:phpcms admin.php