如何通过“问号"在 url javascript 中 [英] how to pass "question mark" in url javascript
问题描述
在 Angularjs 应用程序中,我有一个类似
http://url.com/my_app/#/store/items
的网址.
现在我想附加查询字符串,例如
http://url.com/my_app/#/store/items?page=2
.
但是在 url 中,javascript 对 "?" 进行编码.到我不想要的%3F"
.它应该保持?"仅在 url 中,因为 angularjs $location.search() 不会为%3F"返回任何内容.
如何实现?
In Angularjs app, i have a url like
http://url.com/my_app/#/store/items
.
Now i want to append query string for example,
http://url.com/my_app/#/store/items?page=2
.
but in url, javascript encodes the "?" to "%3F"
which i don't want. It should remain "?" only in the url as angularjs $location.search() returns nothing for "%3F".
How it can be done ?
推荐答案
您的问题中没有足够的细节,所以我假设您使用的是 AngularJS 路由 - 或者至少是 $location service - 在非 HTML5 模式下.如果是这样,#
字符之后的部分从单页应用程序的角度表示您的 URL(更多关于 AngularJS 此处).
There is not enough details in your question so I will assume that you are using AngularJS routing - or at least the $location service - in non-HTML5 mode. If so, the part after the #
character represents your URL from the single-page-application point of view (more about AngularJS here).
如果上述假设是正确的,则意味着您不应该尝试手动"添加或操纵问号.相反,您应该更改 $location
的 search
部分以操作查询字符串(?
之后的部分),然后将添加/删除问号根据需要添加到最终网址.
If the above assumptions are correct it means that you shouldn't try to add or manipulate the question mark "by hand". Instead you should change the search
part of the $location
to manipulate query string (part after ?
) and the question mark will be added / removed to the final URL as needed.
在你的情况下,你可以写:
In your case you could write:
$location.path('/store/items').search('page', 2)
这假设您正在从 JavaScript 操作 URL,如您的问题所述.
This is assuming that you are manipulating URLs from JavaScript, as stated in your question.
这篇关于如何通过“问号"在 url javascript 中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!