2

I am very new to jquery-ui. I want to use this with ajax. (ASP.NET MVC 5) I created jquery-ui-combobox.js and added inside jquery(combobox) functions.

I want to use like this. Is this argument(source) correct ?

    <script>
    $(function () {
        $("#combobox").combobox({source: function (request, response) {
                $.ajax({
                    url: "/Home/GetProjects",
                    dataType: "json",
                    data: {
                        term: request.term
                    },
                    type: "POST",
                    success: function (data) {
                        /*I dont know what I should here*/
                         })
                        );
                    }
                });});
        $("#toggle").click(function () {
            $("#combobox").toggle();
        });
    });
</script>

Controller :

        public JsonResult GetProjects(string term)
    {
        var list = new List<SelectListItem>();
        list.Add(new SelectListItem { Value = "1", Text = "ActionScript" });
        list.Add(new SelectListItem { Value = "2", Text = "AppleScript" });
        list.Add(new SelectListItem { Value = "3", Text = "Asp" });
        var res = list.Where(p => p.Text.Contains(term));
        return Json(res , JsonRequestBehavior.AllowGet);
    }


                                                                                                Please help.

1 Answer 1

1

In Success You can do like this...

 $("#combobox").append("<option value=''>Select</option>");
                    $.each(data, function (value, key) {
                        $("#combobox").append("<option value='"+key.Value+"'>"+key.Text +"</option>");
                    });
Sign up to request clarification or add additional context in comments.

1 Comment

Ok. I added; thank you @Raghava Nalkari . But $.Ajax not triggered.

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.