0

So currently, I have my url like this: http://localhost:8000/fund_monitor/fund_details/fundaccountid=4&transmission=3&startDate=2017-08-01&endDate=2017-08-02/

Then when I redirect the url using windows.location.replace(url), the url becomes like this: http://localhost:8000/fund_monitor/fund_details/fundaccountid%3D4&transmission%3D3&startDate%3D2017-08-01&endDate%3D2017-08-02/

So the equal sign gets converted to another format. Is there a way to retain the original format?

Thanks

5
  • 2
    Doesn't seem to cause an issue for me on Chrome latest. Which browser are you using? Commented Aug 24, 2017 at 13:29
  • well why is it not a querystring? It is being urlencoded.... Commented Aug 24, 2017 at 13:30
  • I am using Chrome :/ Commented Aug 24, 2017 at 13:30
  • does it do the same i you use windows.location.href = url;? Commented Aug 24, 2017 at 13:31
  • Shouldn't the url be http://localhost:8000/fund_monitor/fund_details/?fundaccountid=4&transmission=3&startDate=2017-08-01&endDate=2017-08-02/ (notice the ? separating the path from the data) or something like that? Special characters like = and & are not allowed as is in the path, that's why they get encoded, but they are expected in the query string. Commented Aug 24, 2017 at 13:32

2 Answers 2

4

It might be because the URL is not in a valid format. It's format is roughly protocol://host:port/path?query_params[1], where query_params looks like a=1&b=2 etc. But you do need the ? to separate the path from your parameters. Whatever you're using seems to treat the part fundaccountid=4&transmission=3&startDate=2017-08-01&endDate=2017-08-02/ as a path, and url encodes it so it can be a proper path. Perhaps try to write the URL as: http://localhost:8000/fund_monitor/fund_details?fundaccountid=4&transmission=3&startDate=2017-08-01&endDate=2017-08-02 and see if that works.

Though it will mean some changes to your backend.


[1] The full format you can see on Wikipedia or RFC 3986

Sign up to request clarification or add additional context in comments.

Comments

2

You can use decodeURIComponent().

The decodeURIComponent() function decodes a Uniform Resource Identifier (URI) component previously created by encodeURIComponent or by a similar routine.

var url = 'http://localhost:8000/fund_monitor/fund_details/fundaccountid%3D4&transmission%3D3&startDate%3D2017-08-01&endDate%3D2017-08-02/';

console.log(decodeURIComponent(url));

3 Comments

Good and reliable answer
This is sort of the reverse of the correct answer. He wants to know why his URL is being encoded, not how to encode it.
@torazaburo Just attached the wrong description. The code snippet was correct to get the decoded URL but its explanation was wrong. Corrected it. Thanks for pointing out.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.