开发者

Jquery UI Autocomplete how to send multiple values to serverside?

I am using the Jquery ui autocomplete and I am wondering how do I send multiple values back.

I tried

$('#id').autocomplete
            ({
                source: 'MyURL',
                minLength: 2,
                extraParams: { Id: 1 }
            });

This does not seem to work. Option for auto complete

Edit

I now have this

$('#id').autocomplete({      
                source: function (request, response)
                {
                    $.ajax({
                        url: 'url',
                        data: {
                            term: request.term,
                            Id: 1
                        },
                        success: function (data)
                        {
                            response(data);
                        }

                    });
                },
                minLength: 2
            });

My controller

 return Json("Test",JsonRequestBehavior.AllowGet);

I also tried

 return Content("Test");

However now I get 'T', 'E', '开发者_如何学编程S', 'T' instead of "Test" It is splitting it up for some reason.


You're close; The autocomplete widget expects an array of candidates back:

This data should be filtered based on the provided term, and can be in any of the formats described above for simple local data (String-Array or Object-Array with label/value/both properties)

return Json(new[] {"Test"}, JsonRequestBehavior.AllowGet)


You can use the option for autocomplete to accept multiple values: http://jqueryui.com/demos/autocomplete/#multiple
From there you can just send the entire value and split it out on a delimiter (probably the comma) and send each one into an array and work on the values from there.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜