Javascript Url替换

时间:2017-08-24 13:26:40

标签: javascript

目前,我的网址是这样的:http://localhost:8000/fund_monitor/fund_details/fundaccountid=4&transmission=3&startDate=2017-08-01&endDate=2017-08-02/

然后,当我使用windows.location.replace(url)重定向网址时,网址就像这样:http://localhost:8000/fund_monitor/fund_details/fundaccountid%3D4&transmission%3D3&startDate%3D2017-08-01&endDate%3D2017-08-02/

因此等号转换为另一种格式。有没有办法保留原始格式?

由于

2 个答案:

答案 0 :(得分:4)

可能是因为网址格式不正确。它的格式大致为protocol://host:port/path?query_params [1],其中query_params看起来像a=1&b=2等。但您需要?将路径与参数分开。无论您使用什么似乎都将部分fundaccountid=4&transmission=3&startDate=2017-08-01&endDate=2017-08-02/视为路径,并且url对其进行编码以使其成为正确的路径。也许尝试将URL写为:http://localhost:8000/fund_monitor/fund_details?fundaccountid=4&transmission=3&startDate=2017-08-01&endDate=2017-08-02 看看是否有效。

虽然这意味着你的后端会有一些变化。

[1]您可以在WikipediaRFC 3986

上看到的完整格式

答案 1 :(得分:2)

您可以使用decodeURIComponent()

  

decodeURIComponent()函数解码先前由encodeURIComponent或类似例程创建的统一资源标识符(URI)组件。



Where debtor_cohort_id Like '{0} + {2}' And ...