asp.net C# jQuery Tokenize2 suggestion not show

199 views Asked by At

I try using jQuery tokenize2 with asp.net/C#, I try to get suggestions from ajax. When I try to inspect, firebug or visual studio, there is no error, but the tokenize2 not working.

here are the code:

Webservice:

[WebMethod]
    [ScriptMethod(ResponseFormat = ResponseFormat.Json)]
    public string GetRelated(string search)
    {

        SearchEntity[] arrEnt = new SearchEntity[]
        {
            new SearchEntity()
            {
                Value = "value 1",
                Text = "text 1"
            },
              new SearchEntity()
             {
                 Value = "value 2",
                Text = "text 2"
             }
        };

        return JsonConvert.SerializeObject(arrEnt, Newtonsoft.Json.Formatting.Indented);

    }

Javacript:

 <script>
    $(document).ready(function () {
        $('.autoCom').tokenize2({
            dataSource: function(term, object) {
                $.ajax('GetData.asmx/GetRelated', {
                    data: { search: term, start: 0 },
                    dataType: 'json',

                    success: function(data) {
                        var $items = [];
                        $.each(data, function(k, v) {
                            $items.push(v);
                        });
                        object.trigger('tokenize:dropdown:fill', [$items]);
                    }
                });
            }
        });
    });
</script>

Please tell me, is there something wrong with the code?

0

There are 0 answers