前端向后端穿的参数包含&,如何解决?

使用 encodeURIComponent() 对 URI 进行编码:

对URL不进行编码的情况下:
window.location.href= '{% url 'b' %}?num=aaa&aa'
 num 的值就会为 aaa,因为&是拼接参数

对URL进行编码:
var url = encodeURIComponent('{% url 'b' %}?a=aaa&aa')
window.location.href= url
这样 num 的值就会为 aaa&aa。

 

posted @ 2021-12-31 16:02  小渔儿  阅读(330)  评论(0)    收藏  举报