How to display remote results with Twitter Typeahead?

Detection score: 5.0

<p>I have a similar problem.
I create this ajax function to get response from my server:</p>

<pre><code>var res = function parseResult(query,response)
{
    $.ajax({
    type: "post",
    url: "users/search_user",
    data: 'query=' + query,            
    dataType: "html",
    type: "POST",
    success: function (result) {
        result = $.parseJSON(result)
        response( $.map( result, function( item ) {
            console.log("item:"+item);
            return item;

        } ) );
        console.log(response);
    }
});

};
</code></pre>

<p>I'm using the following script with twitter typeahead:</p>

<pre><code>$('.typeahead').typeahead(
        { minLength: 1 },
        { source:res}
    );
</code></pre>

<p>and this is my html code:</p>

<pre><code>&lt;label class="demo-label"&gt;Search:&lt;/label&gt; &lt;input type="text" name="country" class="typeahead" /&gt;
</code></pre>

<p>the "map" function works fine, but the response variable not set the list of items and then the typeahead function not append the results. what am I doing wrong?</p>
Posted 11 days ago | reported 11 days ago
Posted by Luca Colombini (1)

Caught by 3 reasons: