此时经过浏览器访问时,链接中中文字符“+”被转义会被为%20

我们会发现利用 decodeURIComponent解码时,%20会被我们解码成' '(空格),从而导致解密失败,提取不到我们想要的参数;

解决办法:

将拿到的地址链接中的%20全部替换成'+',然后进行decodeURIComponent解码;

var url = location.href; //取得整个地址栏
var num = url.indexOf("?");
var param = url.substr(num + 1); //获取整个参数串    
param = decodeURIComponent(param.replace(/%20/g,"+"))

(如有更好的解决办法还请多多指教)

问题 : url 请求参数 多了一个’% 20 ’,导致请求报错 我需要通过 url 传递一个Id,那我的请求应该是: http://192.168.26.59:18000/RegistryCS/macromolecule/STN_179 但是真实传递过去后却成了: http://192.168.26.59:18000/RegistryCS/macromolecule/% 20 STN_179 结果:由于多传递了一个% 20 导致报错; 原因:这个id在我传递前字符串前面多了一个空格,由于不容易看到,所以导致我传递的id其实
1. 为什么会有这个 问题 ? chrome浏览器的根目录文件夹 有一个文件是version.dll,这是一个第三方文件,作用是禁用chrome停止开发者模式提示的第三方插件,正是此文件的存在导致了打开外链失败。 2. 解决此 问题 正如上面所说,我们只需要删除version.dll即可。 找到version.dll 右键单击chrome,打开文件所在位置; 找到version.dll 左键选 ,按一下delete即可。 重启Chrome,完美解决。
最近在使用decodeURIComponent的时候,发现浏览器参数 含有特殊符 %,会导致decodeURIComponent等解码报错。今天就简单分享一下如何处理这个 问题 。 浏览器 的不安全字符 不安全符 Url 在传输的过程,或者用户在排版的过程,或者文本处理程序在处理 Url 的过程,都有可能引入无关紧要的空格,或者将那些有意义的空格给去掉 引 以及<> 引 和尖括 通常用于在普通文本 起到分隔 Url 的作用 通常用于表示书签或者锚点 下面展示一段代码String path = getClass().getResource("/").getPath();或String path = getClass().getClassLoader.getResource("").getPath();  如果当前路径 包含了空格,则返回的路径字符串空格则被转义为(% 20 ),如何解决这个 问题 呢? String path = getClas...
Url 参数 出现+、空格、=、%、&、#等字符的解决办法 原文 链接 :http://www.jeffjade.com/ 20 15/04/16/ 20 15-04-16-deal- url -special-char/ Url 出现了有+,空格,/,?,%,#,&,=等特殊符 的时候,可能在服务器端无法获得正确的参数值,抑或是造成不能正常下载文件(作为Download Url 时候),如何是好?解决办法:就是需要将这些字符转化成服务器可以识别的字符;但是为何 Url 有这些字符就会出现 问题 呢?这就得涉及到 URL
<label for="food-name">食物名称:</label> <input type="text" id="food-name" name="food-name" required> <label for="food-calories">卡路里:</label> <input type="number" id="food-calories" name="food-calories" required> <label for="food-date">日期:</label> <input type="date" id="food-date" name="food-date" required> <button type="submit">添加</button> </form> <table> <thead> <th>食物名称</th> <th>卡路里</th> <th>日期</th> </thead> <tbody> <td>炒饭</td> <td>500</td> <td> 20 21-01-01</td> <td>牛肉拉面</td> <td>700</td> <td> 20 21-01-02</td> <td>烤鸡腿</td> <td>400</td> <td> 20 21-01-03</td> </tbody> </table> ```css .food-record { max-width: 800px; margin: 0 auto; table { border-collapse: collapse; width: 100%; th, td { border: 1px solid #ddd; padding: 8px; text-align: left; background-color: #f2f2f2; JavaScript: ```javascript const form = document.querySelector('form'); const tbody = document.querySelector('tbody'); form.addEventListener('submit', (event) => { event.preventDefault(); const foodName = event.target.foodName.value; const foodCalories = event.target.foodCalories.value; const foodDate = event.target.foodDate.value; const row = ` <td>${foodName}</td> <td>${foodCalories}</td> <td>${foodDate}</td> tbody.insertAdjacentHTML('beforeend', row); event.target.reset(); 这段代码实现了一个简单的饮食 记录 功能,用户可以输入食物名称、卡路里和日期,然后点击添加按钮将数据添加到表格 。用户输入的数据会被存储在表格 ,以便用户随时查看和修改。
CSDN-Ada助手: 非常感谢博主分享关于前端链接地址中‘+’被编码为%20问题的记录。我觉得博主可以继续深入探讨关于URL编码的知识,比如如何处理其他特殊字符等等。这样的技术文章对其他前端开发者来说一定会很有帮助。下一篇你可以写一篇《深入解析URL编码》,相信会有更多读者受益。加油! 为了方便博主创作,提高生产力,CSDN上线了AI写作助手功能,就在创作编辑器右侧哦~(https://mp.csdn.net/edit?utm_source=blog_comment_recall )诚邀您来加入测评,到此(https://activity.csdn.net/creatActivity?id=10450&utm_source=blog_comment_recall)发布测评文章即可获得「话题勋章」,同时还有机会拿定制奖牌。