javascript - Autocomplete: Why will my response object not return both first and last name ? -
i'm totally new jquery autocomplete using ajax. have got 90% way there code below. using chrome dev tools can see all values coming through next firstname:item.firstname1
, say, firstname,lastname, telephone etc. , if have 3 matches displayed sequentially. screw things up. lastname
, telephone
objects appear redundant , nothing appears next them. furthermore none of values appear options on screen. however, 3 empty options show 3 objects found. select:function(event, ui)
not work either. have read docs 100 times not getting anywhere fast.
i'd grateful if work, explain have done wrong. tks !
javascript:
$('#customer').autocomplete({ minlength: 2, source: function(request, response,term) { var param = request.term; $.ajax({ url: "quotes/customer_search/"+param, datatype: "json", type:"get", success: function (data) { response($.map(data, function(item) { return { firstname:item.firstname1, // objects appear here. lastname:item.lastname1, // these redundant telephone:item.telephone1, // redundant }; }));//end success }, });//end ajax }, select: function( event, ui ) { log( ui.item ? "selected: " + ui.item.firstname + " " + ui.item.lastname : "nothing selected, input " + this.value ); }
html
<div class="ui-widget"> <label for="customer">birds: </label> <input id="customer" class="ui-autocomplete-input" > </div> <div class="ui-widget" style="margin-top:2em; font-family:arial"> result: <div id="log" style="height: 200px; width: 300px; overflow: auto;" class="ui-widget-content"></div> </div>
i found answer helped me solve problem:
once had looked @ had realized syntax reponse object needed changing code below. once changed worked.
success: function (data) { response($.map(data, function(item,customer) { return [item.firstname1+' '+item.lastname1+' '+item.telephone1] }));//end success },