2013-05-13 25 views
0

我正在使用Jquery標籤 - 它從遠程JSON字符串獲取關鍵字列表 - 這工作正常。jQuery與Mod_Rewrite從somefile.php更改請求?q = foo到/ somefile/foo?

但是什麼現在我有了在這裏,而不是jQuery的「向下鑽取」鍵入其試圖做

somefile.php?q中的搜索查詢的情況= foo的

(富是你剛剛輸入的內容,這將向下鑽取的標籤列表,只在其中顯示那些「富」。

我使用Laravel 4,所以我需要根本上改變了ajax請求它,而不是/somefile/foo。是否有任何w是否這樣做?我一直在瘋狂地尋找,但找不到解決方案。

僅供參考,這裏的標籤,它的代碼,我目前有:

$("#tags").tagit({ 
    autocomplete: {delay: 0, minLength: 2}, 
    allowSpaces: true, 
    onlyAvailableTags : false, 
    tagSource: function(search, showChoices) 
    { 
     var that = this; 
     $.ajax({ 
      url:  "/admin/keywords/autocomplete", 
      data: { term:search.term }, 
      dataType: "json", 
      success: function(choices) 
      { 
       showChoices(that._subtractArray(choices, that.assignedTags())); 
      } 
     }); 
    } 
}); 

回答

0

好吧,我想我已經成功通過試驗和錯誤來解決這個出自己 - 這現在工作。

我調整Laravel路由,這樣下面的路徑將做一個「%LIKE%」 SQL上的任何東西在它拋出查詢:

http://domain.com/admin/keywords/autocomplete/search/{term} 

使用這個我修改了TAG-IT插件中的Ajax調用而是將輸入追加到url的末尾。最終的代碼如下所示:

$("#tags").tagit({ 
    autocomplete: {delay: 0, minLength: 2}, 
    allowSpaces: true, 
    onlyAvailableTags : false, 
    tagSource: function(search, showChoices) 
    { 
     var that = this; 
     $.ajax({ 
      url:  "/admin/keywords/autocomplete/search/" + search.term, 
      // data: { term:search.term }, 
      dataType: "json", 
      success: function(choices) 
      { 
       showChoices(that._subtractArray(choices, that.assignedTags())); 
      } 
     }); 
    } 
}); 

這似乎工作,並且是令人驚訝的瞬間。我知道有可能有更好的方法來做到這一點,但這是我現在能做的最好的。