2

How can I load json datas with ajax in EasyUI combobox?

    $('#cc').combobox({
        valueField: 'id',
        textField: 'text',
        data: function (request, response) {
            $.ajax({
                url: '@Url.Action("GetBranchesByCustomer","WidgetFeatures")',
                type: "POST",
                dataType: "json",
                data: { term: request.term },
                success: function (data) {
                    response($.map(data, function (item) {
                        return { id: item.id, text: item.name };
                    }))

                }
            })
        }
    });

I tried this script, but it didn't work. Where is my mistake?

Although I add "id" parameter like below, this script gives me this error: Uncaught TypeError: Cannot read property 'id' of undefined

<input id="cc" name="dept" value="aa">
mustafaalkan64
  • 207
  • 1
  • 3
  • 13
  • 1
    try changing `response($.map(data, function (item) {` to `response($.map(data.d, function (item) {`. – th1rdey3 Dec 10 '13 at 17:53

1 Answers1

1

I solved the problem. It doesnt need ajax for load json datas. Because already "GetBranchesByCustomer" method returns json data. Scripts are below :

  $('#cc').combobox({
    valueField: 'id',
    textField: 'text',
    url: '@Url.Action("GetBranchesByCustomer","WidgetFeatures")'
});
mustafaalkan64
  • 207
  • 1
  • 3
  • 13