5

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,

1
  • I tried several variations on the callback for success: success: function( data ) { response( data ) ; } , e.g. Commented Feb 7, 2011 at 13:54

1 Answer 1

4

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

Sign up to request clarification or add additional context in comments.

Comments

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.