开发者

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,


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

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜