2012-02-07 10 views
0

使用此jQuery插件:http://archive.plugins.jquery.com/project/query-object查詢字符串轉換插件到+%2B

所以我有這個網址:results?search_query=alex+voievod,我需要添加&page=2,我做它與提到的插件。

現在的問題是,它將+轉換爲%2B,它會影響我的查看頁面。我曾嘗試設置spaces: false,因爲它的文件中說,(即使是spaces: VALUEspace

但它不會工作,它增加了參數,但如上所述也改變+:

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

+0

可以喲顯示你的代碼如何使用它?你使用'toString'方法來獲取組合字符串? – ShankarSangoli 2012-02-07 17:15:26

回答

0

看它的源代碼,我看你,如果你因爲它將它們轉換爲(空格),然後使用toString()將它們轉換回+,因此您的奇怪字符串中有+,然後將其設置爲spacetrue。嘗試這個。

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

我在編輯中添加了使用'$ .query'的代碼。 '.toString()'被使用,我仍然在檢查源代碼,看看這可能是什麼原因造成的,因爲如果將'true'或'false'設置爲'spaces',則輸出相同的結果。 – Alex 2012-02-07 17:34:46