查询字符串插件转换 +至%2B

发布于 2025-01-03 21:39:46 字数 1869 浏览 2 评论 0原文

使用此 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

删除会话 2025-01-10 21:39:46

看看它的源代码,我发现如果你的查询字符串中有 + ,那么将 space 设置为 true 因为它将它们转换为 < code>(空格),然后使用 toString() 将它们转换回 +。试试这个。

$.query = { spaces: true };
$.query.toString();

Look at its source code, I see you that if you have + in your query string then set space to true because it converts them to (space) and then using toString() converts back them to +. Try this.

$.query = { spaces: true };
$.query.toString();
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文