2011-08-06 224 views
2

我正在使用自动完成jQuery。我起诉的代码是这样的:自动完成jquery

$(function() {   
     $("#search").keyup(function(){ 
      var cat=$("#categoryTag option:selected").text(); 
      var url = "${resource.path}.suggestion.$"+this.value+".$"+cat+".json"; 
      $(this).autocomplete({    
        source: url, 
        minLength: 2, 
        appendTo: "#search_results_div" 
       }); 
     }); 

它工作正常,但我得到的网址是这样的http://servername/pagename/suggestion.textboxValue.dropdownValue?term=textBoxVale

我的问题是如何避免查询字符串,因为我想我的网址是这样的 http://servername/pagename/suggestion.textboxValue.dropdownValue

请给我指点。在此先感谢

回答

1

source可以在其中您可以阿贾克斯你想要的任何URL的回调:

$("#search").autocomplete({ 
    source: loadFromAjax, 
    minLength: 2, 
    appendTo: "#search_results_div" 
}); 

function loadFromAjax(request, response) { 
    $.ajax({ 
     url: '/your/url/here/' + encodeURIComponent(request.term)), 
     dataType: 'json', 
     success: function(data) { 
      // you can format data here if necessary 
      response(data); 
     } 
    }); 
} 
+0

@马克thanx的rply ...但它仍然有一个问题... ...它去掉了查询字符串“ term =',但仍然给我的查询字符串参数的值....现在形成的url是http://servername/pagename/suggestion.textboxValue.dropdownValue 但我什么是** http://服务器名/网页/ suggestion.textboxValue.dropdownValue * – Avi