views:

132

answers:

2

I'm trying to get an autocomplete field firing in my asp.net mvc website. Basically the user types in their location and i go out to my db and pre-populate with country and postcodes that match.

The problem im having is that when the view load an error throws saying "Microsoft JScript runtime error: Exception thrown and not caught". It is throwing in the jquery.Ui.widget.js file at the following line:

throw "cannot call methods on " + name + " prior to initialization; " +
                    "attempted to call method '" + options + "'";

Following is my script:

<script type="text/javascript" language="javascript">
$(function () {
    $.ajaxSetup({ type: "POST" });
    $('#Location').autocomplete('<%= Url.Action("Find") %>', {
        dataType: 'json',
        parse: function (data) {
            var rows = new Array();
            for (var i = 0; i < data.length; i++) {
                rows[i] = { data: data[i], value: data[i].PlaceName, result: data[i].PlaceName, id: data[i].LocationID };
            }
            return rows;
        },
        formatItem: function (row) {
            return row.PlaceName;
        },
        delay: 300,
        autofill: true,
        selectFirst: true,
        highlight: false

    }).result(function (event, row) {
        $("input[id$='LocationID']").val(row.LocationID);
    });
});
</script>

I've made sure all the needed jquery files are attached but still cant get it to fire. Ive got the simple default functionality of the autocomplete control to fire (showing a prepopulated list), but as soon as i try to pull from a Json datatype it gives me grief.

Any ideas?

A: 

I'm a beginner, but I just posted the question http://stackoverflow.com/questions/3767696/asp-net-mvc-jquery-ui-autocomplete-list-not-showing-up-when-i-debug

Mine is firing when I look at a the console in Firebug and I get my results, but the list still isn't displaying on the screen. Perhaps looking at my code will show you another way to look at it...

Ben
A: 

You can check out my answer to Ben here, hopefully it will help you too.

mare