I'm trying to set up jQuery Autocomplete, I wrote this code:

$("#name_input").autocomplete({ source: 'Home/MessageHandler', minLength: 1, select: function (event, ui) { log("Selected: " + ui.item.value); } }); }); 

And such a controller (using ASP .Net Core):

 public JsonResult MessageHandler() { string result = "[{label:'string1',value:'string2'},{label:'string3',value:'string4'}]"; return Json(result); } 

If I go directly to the controller: http: // localhost: 3140 / Home / MessageHandler then everything is OK, I get the line:

 [{label:'string1',value:'string2'},{label:'string3',value:'string4'}] 

But if you enter a request into the input to which the autocomplit event is connected, autocomplete does not appear , and the download icon appears in the input line, which no longer disappears from there (see screen3). I attach server response screens:

Headlines:

Server response

Server response

Reply from server2

Icon that does not disappear

Line input with icon that does not disappear

    1 answer 1

    The problem was that the controller gave the wrong json, rewrote it like this:

     public IActionResult MessageHandler() { var result = new[] { @"ActionScript", "AppleScript", "Asp", "BASIC", "C", "C++", "Clojure", "COBOL", "ColdFusion", "Erlang","Fortran", "Groovy","Haskell", "Java", "JavaScript", "Lisp", "Perl", "PHP", "Python","Ruby", "Scala", "Scheme" }; return Json(result); } 

    And everything became ok. Now the answer from the server looks like this: enter image description here

    If someone tells you where the dog rummaged, they will be grateful.