开发者

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

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开发者_如何学JAVA with it? when i stick an / in between the quotes it works but my content doesnt load.


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


unescape is deprecated, use

decodeURI(url)
decodeURIComponent(url)


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".


Try with urldecode() or rawurldecode() in your AJAX request.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜