How do i replace %2F in my ajax requested URL?

10,047

Solution 1

Use:

unescape(url)

to convert the %2F to a /. The url.replace line you mention would strip the url up to and including a # character, so:

http://mysite.com/Content/#Disc/index

would become:

Disc/index

Solution 2

unescape is deprecated, use

decodeURI(url)
decodeURIComponent(url)

Solution 3

Your browser is doing the right thing. %2F is the HTTP-encoded / character, and technically speaking it should be there in the anchor tag. Locations aren't optimised for human-viewing but to be "correct".

Share:
10,047
Ricki
Author by

Ricki

Updated on June 04, 2022

Comments

  • Ricki
    Ricki almost 2 years

    Im using jQuery, my problem..

    my URL looks like this after an ajax request (using hashchange function to enable history) :

    mysite.com/Content/#Disc%2Findex

    I want it to look like this:

    mysite.com/Content/#Disc/index

    I noticed this line in my js:

    url = url.replace(/^.*#/, '');

    Does this have anything to do with it? when i stick an / in between the quotes it works but my content doesnt load.