0

奇怪的是,这只发生在某些用户身上。

Started POST "/search_category/autocomplete" for 172.29.11.20 at Wed Jun 12 10:51:23 -0700 2013
Processing by SearchCategoryController#autocomplete as 
Parameters: {"term"=>"a"}
Redirected to http://server.domain.com/
Completed 302 Found in 30ms

服务器代码:

def autocomplete
  term = params[:term].strip
  respond_to do |format|
    format.json { render :json => SearchCategory.select("name, path").where('display_name  like ?', "#{term}%").to_json }
  end
end

客户端代码:

$("#category").autocomplete({
    source: function(request, response){
        $.ajax({
            url: "/search_category/autocomplete",
            type: "POST",
            dataType: "json",
            data: {
                term: request.term
            },
            success: function(data){
                var array = data.map(function(element) {
                    reverseCatMap[element['path']] = element['name'];
                    return element['path'];
                });
                response(array);
            }
        })
    }
});
4

0 回答 0