jQuery AutoComplete Plugin not working for JSON Response (sValue.substring is not a function)

Posted by Sunday Ironfoot on Stack Overflow See other posts from Stack Overflow or by Sunday Ironfoot
Published on 2010-04-05T09:41:41Z Indexed on 2010/04/05 10:23 UTC
Read the original article Hit count: 453

I'm trying to use the autocomplete plugin for jQuery (this one http://docs.jquery.com/Plugins/Autocomplete). My server is returning JSON string, which I'm trying to process on the client via AutoComplete plugin's 'parse' and 'formatItem' parameters, like so:

$(document).ready(function()
{
    $('.searchBox input.textbox').autocomplete('/DoSearch.aspx',
    {
        mustMatch: false,
        autoFill: true,
        minChars: 1,
        dataType: 'json',
        parse: function(data)
        {
            var array = new Array();
            for (var i = 0; i < data.length; i++)
            {
                array[array.length] = { data: data[i], value: data[i].ID, result: data[i].ID };
            }
            return array;
        },
        formatItem: function(row, i, n)
        {
            return row.ID + ': ' + row.Title;
        }
    });
});

When I run this I get a 'sValue.substring is not a function' error thrown in Firebug. However, if I stick breakpoints on formatItem and parse function, they are hit as expected and contain valid data it seems.

Here is an exact copy 'n' paste of the JSON text that gets returned from the server:

[{"ID":140177,"Title":"Food Handling","Code":"J01.576.423.200"},{"ID":140178,"Title":"Food Handling","Code":"J01.576.423.200"},{"ID":140179,"Title":"Brain Infarction","Code":"C10.228.140.300.301.200"},{"ID":140180,"Title":"Cerebral Hemorrhage","Code":"C10.228.140.300.535.200"},{"ID":140182,"Title":"Insulin","Code":"D06.472.610.575"},{"ID":140183,"Title":"Insulin","Code":"D06.472.610.575"},{"ID":140184,"Title":"Insulin","Code":"D06.472.610.575"},{"ID":140186,"Title":"Insulin","Code":"D06.472.610.575"},{"ID":140188,"Title":"Insulin","Code":"D06.472.610.575"},{"ID":140189,"Title":"Sulfonylurea Compounds","Code":"D02.886.590.795"}]

Please help, I've already searched Google and StackOverflow for help, but can't find anyone having else this error, cheers!

© Stack Overflow or respective owner

Related posts about jQuery

Related posts about autocomplete