Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
189 views
in Technique[技术] by (71.8m points)

为什么url拼接+号不显示

因为缺+号导致接口报错请问为什么url里有,但是到query里缺没了,请问我怎么处理,感谢

console.log(mobile)//+8613771705654
url : '../ticket?mobileNo='+mobile+'&verifyCode='+params.password+'&type=2'
url : '../ticket?mobileNo=%2B'+mobile+'&verifyCode='+params.password+'&type=2'//这样子可以但是 `+ 861377...`中间有个空格

1592993219(1).png


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

值里面有符号的尽量使用encodeURIComponent编译后再解析就不会有问题。

location.href = 'https://ostack.cn/q/1010000023017018?m=' + encodeURIComponent('+131...');

image.png

取到m的值后记得decodeURIComponent(m)一下;


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
...