查询字符串插件转换 +至%2B
使用此 jquery 插件: http://archive.plugins.jquery.com/project/query- object
所以我有这个 url:results?search_query=alex+voievod
并且我需要添加 &page=2
,我用上面提到的来做到这一点插件。
现在的问题是它将 +
转换为 %2B
并且它影响了我的查看页面。我尝试按照文档中的说明设置 spaces: false
(尽管是 spaces: VALUE
不是 space
),
但它不起作用,它添加了参数,但也更改了 +,如上所述:
results?search_query=alex%2Bvoievod&page=2
我缺少什么?
空间
此值的默认值为 true,因为大多数人更喜欢将查询字符串中的加号转换为空格。这是标准的 练习使用加号来表示查询字符串中的空格 避免可怕的 %20,因此解析器已更新,默认情况下, 将加号转换为空格。但是,可以禁用此功能 如果您决定在查询字符串中需要文字加号。
<script type="text/javascript"> $.query = { spaces: false }; </script>
<script src="<?=base_url();?>resources/js/libs/jquery.query.js"></script>
在 jquery.query.js 内部:
new function(settings) {
// Various Settings
var $separator = settings.separator || '&';
var $spaces = settings.spaces === false ? false : true;
alert($spaces);->Returns the value as set, true or false.
var $suffix = settings.suffix === false ? '' : '[]';
我已经阅读了一些代码,但是我找不到错误在哪里,因为 spaces
没有效果。
编辑: 我与 $.query
使用的代码
var cur_page = $.query.get('page');
if (cur_page.length == 0){var next_page = cur_page + 2;}
else { var next_page = cur_page + 1; }
var page = $.query.set('page', next_page).toString();
alert(page);
/*window.location.replace(page);*/
我将尝试联系此插件的创建者:https://github.com/blairmitchelmore/jquery.plugins/blob/master/jquery.query.js
Using this jquery plugin: http://archive.plugins.jquery.com/project/query-object
So I have this url: results?search_query=alex+voievod
and I need to add &page=2
, which I do it with the mentioned plugin.
Now the problem is that it converts +
to %2B
and it and it affects my view page. I have tried setting spaces: false
as it says in the documentation (even though is spaces: VALUE
not space
)
But it won't work, it adds the parameter but it also changes + as mentioned above:
results?search_query=alex%2Bvoievod&page=2
What am I missing?
space
The default value for this is true as most people prefer plus signs in query strings to be converted to spaces. It's standard
practice to use plus signs to represent spaces in query strings to
avoid the dreaded %20 so the parser has been updated and, by default,
converts plus signs to spaces. However, this feature can be disabled
if you decide you need literal plus signs in your query strings.
<script type="text/javascript"> $.query = { spaces: false }; </script>
<script src="<?=base_url();?>resources/js/libs/jquery.query.js"></script>
Inside jquery.query.js:
new function(settings) {
// Various Settings
var $separator = settings.separator || '&';
var $spaces = settings.spaces === false ? false : true;
alert($spaces);->Returns the value as set, true or false.
var $suffix = settings.suffix === false ? '' : '[]';
I have read a bit the code, but I can't find where is the bug having in mind that spaces
has no effect.
Edit:
The code I use with $.query
var cur_page = $.query.get('page');
if (cur_page.length == 0){var next_page = cur_page + 2;}
else { var next_page = cur_page + 1; }
var page = $.query.set('page', next_page).toString();
alert(page);
/*window.location.replace(page);*/
I am going to try and contact the creator of this plugin: https://github.com/blairmitchelmore/jquery.plugins/blob/master/jquery.query.js
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看看它的源代码,我发现如果你的查询字符串中有
+
,那么将space
设置为true
因为它将它们转换为 < code>(空格),然后使用toString()
将它们转换回+
。试试这个。Look at its source code, I see you that if you have
+
in your query string then setspace
totrue
because it converts them to(space) and then using
toString()
converts back them to+
. Try this.