2013-05-13 61 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())); 
      } 
     }); 
    } 
}); 

这似乎工作,并且是令人惊讶的瞬间。我知道有可能有更好的方法来做到这一点,但这是我现在能做的最好的。