2

I am using jQuery UI Autocomplete on my Create View in my web application

When I click in the textbox that I want the autocomplete to service, and type 1 letter, I receive a runtime error:

Runtime Error

Here is the line of the built in script debugger where the error is occurring

line of the built in script debugger where the error is occurring

Here is my Script:

<script type="text/javascript">
$(document).ready(function () {
    $('#Categories').autocomplete({
        source: function (request, response) {
            $.ajax({
                url: "/Activities/AutoCompleteCategory",
                type: "POST",
                dataType: "json",
                data: { term: request.term },
                success: function (data) {
                    response($.map(data, function (item) {
                        return { label: item.subcategory, value: item.subcategory };
                    }))
                }
            })
        },
        messages: {
            noResults: "", results: ""
        }
    });
})
</script>

Here is my Controller:

public JsonResult AutoCompleteCategory(string term)
{
    var result = (from r in db.Activities
                  where r.subcategory.ToUpper().Contains(term.ToUpper())
                  select new { r.subcategory }).Distinct();

    return Json(result, JsonRequestBehavior.AllowGet);
}

If I click Do not show this message again, it works perfectly.

Any help to figure out why this run-time error is happening is greatly appreciated.

1 Answer 1

5

The code that's failing is trying to execute the results method under messages.

this.messages.results(e.length)

You have defined the results method as "" here:

    messages: {
        noResults: "", results: ""
    }

The browser is probably handling this error silently after you cancel the dialog box, but underneath it is still dealing with the error. You should remove the messages section if you have nothing to add there, or create your messages as empty functions.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.