问题
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
回答1:
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();
来源:https://stackoverflow.com/questions/9180357/query-string-plugin-converts-to-2b