0
$(function() {
  $('.autocomplete_address').autocomplete({
    minLength: 0,
    delay: 600,
    source: function(request, response) {
      $.ajax({
        url: "/welcome.js",
      dataType: "json",
      data: {search: request.search},
      success: function( data ) {
      var data_obj = jQuery.each(data,function(i, key) {
                     });
        response( $.map(data_obj, function( item ) {
          return {
            label: item.area,
            value: item.area
          }
        }));
      }


    });
      }

    });


});

Using jquery-ui-186's autocomplete

The autocomplete part works But it shows the same results for any data entered

In the server side code looks like this:

class WelcomeController < ApplicationController

  def index
    @area =  Address.search params[:search]
    @area =  @area.as_json(:include => :state)
    @area =  @area.to_json

    respond_to do |format|
      format.html
      format.js {render :json => @area}
    end
  end

end

Where am i going wrong!!!!!! Any help is greatly appreciated.

2 Answers 2

1

The request object has a term property, not a search property. Update your AJAX call:

/*Snip */
data: { search: request.term },
/*Snip */
Sign up to request clarification or add additional context in comments.

1 Comment

WoW... That works!!!!!!!!!!YAY...**Thanks very much** And I'll vote this up once i reach 15 reputation points
0

Update: make from the docs:

                success: function( data ) {
                    response( $.map( data.geonames, function( item ) {
                        return {
                            label: item.name + (item.adminName1 ? ", " + item.adminName1 : "") + ", " + item.countryName,
                            value: item.name
                        }
                    }));
                }

So yours might look like this:

 success: function( data ) {
                    response( $.map(data_obj, function( item ) {
                       return {
                          label: item.area,
                          value: item.area
                       }
                 });
    }

It looks like you're not actually doing anything with the results of your .each().

3 Comments

Nope That's not it...Some how the data that is to be sent to the sever for lookup is getting sent Is data: {search: request.search}, correct? I am not sure....
Nope That's not it...Some how the data that is to be sent to the sever for lookup is getting sent
I added that $.each block just to get the objects separately in a variable so that i can work on that...Other that each() is not being used like you said....But It's working now thanks to @orolo

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.