js 报错:Uncaught URIError: URI malformed

报错:

Uncaught URIError: URI malformed

原因:

decodeURI转码时,通过%进行解析,如果字符串中存在%(如: ‘100%’),则会出现URI malformed

解决方案:将  % 替换成  %25

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

 

posted @ 2024-05-15 14:19  唏嘘-  阅读(302)  评论(0编辑  收藏  举报