以下是我的JS代码:
window.location.href = 'products.php?price_range=-INFto2000,2001to5000';
我的问题是如何用javascript编码URL并用PHP解码URL,以便浏览器的导航栏将显示
“ products.php?price_range = -INFto2000%2C2001to5000”
代替
“ products.php?price_range = -INFto2000,2001to5000”
和我的PHP代码将能够使用-INFto2000,2001to5000
in的适当值$_GET['price_range']
在您的JavaScript代码中尝试一下
window.location.href = 'products.php?price_range='+encodeURIComponent('-INFto2000,2001to5000');
您可以在$ _GET ['price_range']中访问解码后的值。$ _GET变量默认在PHP中被解码。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句