本文介绍了如何通过"问号"在JavaScript的网址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Angularjs应用程序,我有一个像
http://url.com/my_app/#/store/items 的URL。

现在我想追加查询字符串,例如,
http://url.com/my_app/#/store/items?page=2

但在URL,JavaScript的EN codeS的?为%3F我不想要的。它应该保持?仅在网址为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路由 - 或至少是的 - 非HTML5模式。如果是这样,字符重新$ P $之后的部分psents但从单页的应用程序,点您的网址(更多关于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).

如果上述假设是正确的就意味着你不应该试图手动添加或操纵问号。相反,你应该修改搜索 $位置来操纵查询字符串(部分的一部分?)和问号将被添加/删除根据需要最终的网址。

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操纵的网址,因为在你的问题说明。

This is assuming that you are manipulating URLs from JavaScript, as stated in your question.

这篇关于如何通过"问号"在JavaScript的网址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-21 02:29