views:

76

answers:

1

When I use JQuery's autocomplete and hardcode the array values in the page it works wonderful; but what I need to do is obtain the array values from either a web service or from a public function inside a controller. I have tried various way and can't seem to make it work. The farthest I got is pulling the data in to a long string and when the auto complete results are provided it's the long string which matches, which I understand why.

    $("#TaskEmailNotificationList").autocomplete("http://localhost/BetterTaskList/Accounts/registeredUsersEmailList", {
    multiple: true,
    mustMatch: false,
    multipleSeparator: ";",
    autoFill: true
  });

has anyone encountered this? I am using C#.

UPDATE: The below code is a step forward I am now getting an array returned but I think I'm processing it wrong on my page.

  var emailList = "http://localhost/BetterTaskList/Account/RegisteredUsersEmailList";

  $("#TaskEmailNotificationList").autocomplete(emailList, {
    multiple: true,
    mustMatch: false,
    multipleSeparator: ";",
    autoFill: true
  });

 [HttpGet]
    public  ActionResult RegisteredUsersEmailList()
    {
       BetterTaskListDataContext db = new BetterTaskListDataContext();
        var emailList = from u in db.Users select u.LoweredUserName;
        return Json(emailList.ToList(), JsonRequestBehavior.AllowGet);
    }
A: 

First, your syntax looks different than I am used to. If you are using the autocomplete widget that is part of jQuery UI, then the autocomplete syntax is like this:

$("#input1").autocomplete({
      source: "http://localhost/Whatever"
});

So maybe you are not using the autocomplete that is included in jQuery UI?

In case you are....
According to the documentation for jQuery UI autocomplete, the source can be one of three things; an array, a string (URL), or a function. If it is an array, it can be objects or words. If objects, then each should expose either a label, or a value property or both.

If it is a URL, then it should return JSON that conforms to one of the array formats. Eg, it should return

[ "albatross", "bison", "cayman", "duck", ...] 

or

[ { "label": "albatross", "value": "72" }, 
  { "label": "bison", "value": "24" }, 
   ...
]

Most likely you are retrieving something that does not conform to one of the above formats.

See also, this answer

Cheeso
I am using this autocomplete plugin http://bassistance.de/jquery-plugins/jquery-plugin-autocomplete/ which if I am not mistaken it's an extension of the jquery autocomplete feature. The question you refered me to shed some more light on my issue, now i have to figure out how to return a properly structured array. thanks.
Geovani Martinez