How to encode periods for URLs in Javascript?

后端 未结 8 1995
耶瑟儿~
耶瑟儿~ 2020-12-15 15:29

The SO post below is comprehensive, but all three methods described fail to encode for periods.

Post: Encode URL in JavaScript?

For instance, if I run the th

8条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-15 16:15

    I know this is an old thread, but I didn't see anywhere here any examples of URLs that were causing the original problem. I encountered a similar problem myself a couple of days ago with a Java application. In my case, the string with the period was at the end of the path element of the URL eg.

    http://myserver.com/app/servlet/test.string

    In this case, the Spring library I'm using was only passing me the 'test' part of that string to the relevant annotated method parameter of my controller class, presumably because it was treating the '.string' as a file extension and stripping it away. Perhaps this is the same underlying issue with the original problem above?

    Anyway, I was able to workaround this simply by adding a trailing slash to the URL. Just throwing this out there in case it is useful to anybody else.

    John

提交回复
热议问题