i spending time resolve problem.
i tried make functionaly ajax call bootstrap+typeahead.
if can me, great
this html part :
<div class="control-group"> <label class="control-label">parent</label> <div class="controls"> <input type="text" value="" name="parent" id="parent" autocomplete="off" data-provide="typeahead" /> </div>
this js part :
$(document).ready(function() { $('#parent').typeahead({ source: function (query, process) { return $.ajax({ minlength: 1, url: "/ajax/places/", type: 'post', data : 'query='+query, datatype: 'json', success: function (data) { return typeof data == 'undefined' ? false : process(data); } }); } }); });
i can see ajax fired, , json, here extract :
[ "name": "aix" , "name": "aix" , "name": "aix en diois" , "name": "aix en ergny" , "name": "aix en issart" , "name": "aix en othe" , "name": "aix en provence" , "name": "aix la fayette" , "name": "aix les bains" , "name": "aix noulette" , "name": "aixe sur vienne" , "name": "artaix" , "name": "baix" , "name": "baixas" , "name": "benaix" , "name": "caix" , "name": "caixas" , "name": "caixon" , "name": "carhaix plouguer" , "name": "chaix" ]
if "console.log(data)", seems ok.
thanks !!
it works if remove "name" property, :
[ "aix" , "aix" , "aix en diois" , "aix en ergny" , "aix en issart" , "aix en othe" , "aix en provence" , "aix la fayette" , "aix les bains" , "aix noulette" , "aixe sur vienne" , "artaix" , "baix" , "baixas" , "benaix" , "caix" , "caixas" , "caixon" , "carhaix plouguer" , "chaix" ]
but how can use id , name ?
edit : used bootstrap typeahead ajax result format - example , found solution
i'll show did other process.
the "stuff" returned not valid json, , that's why client-side javascript unable deal it.
if suppose json object, should this:
{ "name1": "aix" , "name2": "aix" , "name3": "aix en diois"
etcetera. (note attribute names need unique. legal in theory have multiple attributes identical names. won't work. json parsers i've ever encountered discard 1 of corresponding values.)
if suppose json array should this:
{ "aix" , "aix" , "aix en diois"
etcetera. or maybe:
[ {"name": "aix"} , {"name": "aix"} , {"name": "aix en diois"}
etcetera, json array of objects.
reference:
Comments
Post a Comment