如何在程序中获取自动完成jquery ajax的id

时间:2017-08-11 12:17:39

标签: jquery ajax autocomplete

如何在程序中获取自动完成jquery ajax的id

$("#firstname")
    .autocomplete({ 
        source: function(request, response) { 
            $.ajax({ 
                url: "search.php", 
                dataType: "json", 
                data: { term: request.term },                                     
                success: function(data) { 
                    response(
                        $.map(data.myData, function(item) {
                            return {
                                label: item.title,
                                value:item.turninId
                            }
                        });
                    )
                }
            });
        }
    });

PS:这是自动填充jquery api:http://api.jqueryui.com/autocomplete/

的文档

1 个答案:

答案 0 :(得分:0)

 $( "#firstname" ).autocomplete({
             source: function( request, response ) {
                  $.ajax( {
                      url: "search.php",
                      dataType: "json",
                      data: {
                        term: request.term
                      },
                      success: function( data ) {
                          response( $.map( data.myData, function( item ) {
                              return {

                                  label: item.title,
                                  value: item.turninId


                              }
                          }));
                      }
                  });
              },
         select: function( event, ui ) {
                    $( "#firstname" ).val( ui.item.label);
                    $( "#fname" ).val( ui.item.value);

                    return false;
                }

          });