encodeURIComponent引发错误"URI格式错误"

编程入门 行业动态 更新时间:2024-10-28 02:26:28
本文介绍了encodeURIComponent引发错误"URI格式错误"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

由于不推荐使用unescape,所以我选择了decodeURIComponent,但是它没有按预期工作. decodeURIComponent无法解码以下URI组件

As unescape has been deprecated I have chosen decodeURIComponent , but it doesn't work as expected . decodeURIComponent cant decode the following URI component

Coast%20Guard%20Academy%20to%20hold%20annual%20Women%92s%20%91Leadhership%92%20event

在解码以上字符串的解码URIComponent时,会抛出错误,从而阻止了其余的javascript执行.

While decoding the above string decodeURIComponent throws an error, which blocks the remaining javascript execution.

是否有解决此问题的解决方案?

Is there is any solution to fix this ?

推荐答案

%91和%92字符是使用ANSI代码页编码的. decodeURIComponent() 期望该字符串已编码为UTF-8 :

The %91 and %92 characters were encoded using an ANSI codepage. decodeURIComponent() expects the string to have been encoded as UTF-8:

decodeURIComponent函数计算URI的新版本,其中encodeURIComponent函数可能引入的每种转义序列和UTF-8编码类型的编码都将替换为其表示的字符.

The decodeURIComponent function computes a new version of a URI in which each escape sequence and UTF-8 encoding of the sort that might be introduced by the encodeURIComponent function is replaced with the character that it represents.

两个引号应编码为%E2%80%98和%E2%80%99.

更多推荐

encodeURIComponent引发错误"URI格式错误"

本文发布于:2023-10-24 09:17:51,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1523553.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:错误   格式   encodeURIComponent   URI   quot

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!