Javascript equivalent to php's urldecode()

a 夏天 提交于 2019-11-27 01:13:40

问题


I wrote a custom xml parser and its locking up on special characters. So naturally I urlencoded them into my database.

I can't seem to find an equivalent to php's urldecode().

Are there any extentions for jquery or javascript that can accomplish this?


回答1:


You could use the decodeURIComponent function to convert the %xx into characters. However, to convert + into spaces you need to replace them in an extra step.

function urldecode(url) {
  return decodeURIComponent(url.replace(/\+/g, ' '));
}



回答2:


Check out this one

function urldecode (str) {
  return decodeURIComponent((str + '').replace(/\+/g, '%20'));
}



回答3:


I think you need the decodeURI function.



来源:https://stackoverflow.com/questions/3431512/javascript-equivalent-to-phps-urldecode

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!