Decoding URL parameters with JavaScript

后端 未结 5 699
离开以前
离开以前 2020-11-27 19:22

This should be a simple task, but I can\'t seem to find a solution.

I have a basic string that is being passed through as a query string parameter like this one:

5条回答
  •  感情败类
    2020-11-27 19:58

    The plus sign is not encoded/decoded. To see the decode function working, you need to pass a encoded URI first. Take a look:

    encodeURI( "http://www.foo.com/bar?foo=foo bar jar" )
    

    Will generate: http://www.foo.com/bar?foo=foo%20bar%20jar, i.e., the encoded URI.

    decodeURI( "http://www.foo.com/bar?foo=foo%20bar%20jar" )
    

    Will generate: http://www.foo.com/bar?foo=foo bar jar, i.e., the decoded URI.

提交回复
热议问题