简体   繁体   English

rails和jquery移动自动完成上的406(Not Acceptable)错误

[英]406 (Not Acceptable) error on rails and jquery mobile autocomplete

I keep getting this 406 (Not Acceptable) error when i type in an autocomplete field. 当我输入自动填充字段时,我不断收到此406(不可接受)错误。

I am using jquery mobile and jquery ui autocomplete and rails 我正在使用jquery mobile和jquery ui autocomplete和rails

here is my jquery 这是我的jquery

$("#request_artist").focus(function(){ 
    $("#request_artist").autocomplete({ 
        source: function(req, add){ 
            $.getJSON(artistRequestUrl, req, function(data) { 
                var suggestions = data.suggestions; 
                add(suggestions);    
            });   
        },
        change: function() {
            $("#request_song").attr("disabled", false); 
            $("#request_submit").attr("disabled", false); 
            $("#request_like_reason").attr("disabled", false); 
            $('.disable_color').css("color", "black");   
        },    
    });
});    

here is my html 这是我的HTML

<div data-role="fieldcontain">
    <label for="search">Artist</label>
    <input type="search" name="password" id="request_artist" value="" />
</div>

here is my rails action 这是我的rails动作

def ajax_artist
  bands = Band.all
  artists = bands.map(&:name).uniq.sort
  filter_input(artists, params[:term])
  Rails.logger.info @all_instances_hash.inspect
  respond_to do |format|
    format.json { render :json => @all_instances_hash}
  end
end

if i look at the logger in the console i get this for @all_instances_hash if i enter the letter c 如果我在控制台中查看记录器,如果我输入字母c,我会得到@all_instances_hash

 {:query=>"c", :suggestions=>["Casting Crowns", "John Mark McMillan"]}

But the autocomplete is not working...any idea 但自动完成功能无效......任何想法

I'd guess that Rails thinks you're asking for HTML back. 我猜Rails认为你要求回复HTML。 Your ajax_artist can only ever respond (sensibly) with JSON so try ignoring the format completely: 你的ajax_artist只能用JSON做出明智的回应,所以试着完全忽略这个格式:

def ajax_artist
  bands = Band.all
  artists = bands.map(&:name).uniq.sort
  filter_input(artists, params[:term])
  Rails.logger.info @all_instances_hash.inspect
  render :json => @all_instances_hash
end

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM