美文网首页
关于decodeURI转译报错Uncaught URIError

关于decodeURI转译报错Uncaught URIError

作者: l2en | 来源:发表于2019-07-23 09:01 被阅读0次

出现如下报错:Uncaught URIError: URI malformed

原因:

由于decodeURI转码时,通过%进行解析,如果字符串中存在%(如: ‘0.9%氯化钠注射液’),则会出现URI malformed

解决:

将字符串中的%替换为25%

const percent2percent25 = (URI) => {
  if(URI.indexOf('%') > -1) {
    return URI.replace(/%/g,'%25')
  }else{
    return URI;
  }
}

相关文章

网友评论

      本文标题:关于decodeURI转译报错Uncaught URIError

      本文链接:https://www.haomeiwen.com/subject/vounlctx.html