开发者

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

开发者 https://www.devze.com 2023-04-07 01:43 出处:网络
I keep getting this 406 (Not Acceptable) error when i type in an autocomplete field. I am using jquery mobile and jquery ui autocomplete and rails

I keep getting this 406 (Not Acceptable) error when i type in an autocomplete field.

I am using jquery mobile and jquery ui autocomplete and rails

here is my 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

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

here is my rails action

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

 {:query=>"c", :suggestions=>["Casting Crowns", "John Mark McMillan"开发者_如何学Go]}

But the autocomplete is not working...any idea


I'd guess that Rails thinks you're asking for HTML back. Your ajax_artist can only ever respond (sensibly) with JSON so try ignoring the format completely:

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
0

精彩评论

暂无评论...
验证码 换一张
取 消