jaybee
jaybee

Reputation: 1925

Handling data from a custom source in jquery-ui autocomplete

I am trying to use jquery-ui for autocompletion in a search field. Because the search depends on the value of another form field, I'm using a callback for the source. I can see that the request is sent correctly. My remote script returns a simple array of strings and it's at that point that I can't get it to work. The dropdown list is never built. Can anyone tell me why? Here's the code:

    $(document).ready(function(){
    $("#species").autocomplete({
      source: function( request, response ) {
        $.ajax({
          url: "/includes/species-ajax.cfm",
          dataType: "jsonp",
          data: {
            term: request.term,
            searchBy : function() { 
              var sb = $("#searchBy_hidden").val();
              return (sb ? sb : 'common_name'); }
          },
          success: function( data ) {
            response( $.map( data, function( item ) {
              return {
                label: item.name,
                value: item.name
              }
            }));
          }
         });
    }});
  });

<input type="hidden" name="searchBy_hidden" id="searchBy_hidden" value="common_name" />
Enter the name of a species: <input type="textbox" size="30" id="species" />

Thanks,

Upvotes: 5

Views: 2280

Answers (1)

davin
davin

Reputation: 45525

Try changing your dataType to 'json', not 'jsonp'

Upvotes: 4

Related Questions