I have a working example of JQuery CatComplete, however I am having difficulty getting the example to work with an AJAX variable. Unable to find examples of CatComplete with $ajax request, versus Autocomplete examples which are plentiful.
Below is the data the example uses, which works, but I want to set data to the result of an AJAX request.
var data = [
{ "label": "Test1, "category": "Artist" },
{ "label": "Test2", "category": "Artist" },
{ "label": "Test3", "category": "Musician" }
];
Desired data set:
var data = $.ajax({
url: "/People/AutoComplete",
type: 'POST',
dataType: 'json',
data: { Prefix: $("#search").val() },
success: function (data) {
data= JSON.stringify(data);
alert(data);
}
When using the second approach, the initial page load has no data -- then the function seems to fire again and has data but the autocomplete does not work. I have checked that the resulting object matches the same structure as the explicit var data =.
Ultimately, the attempt is to use the following example, but with AJAX request for datasource: https://jqueryui.com/autocomplete/#categories