0

My KendoUI Autocomplete example works in Chrome but not in Firefox.

I am able to type in a town name e.g. "watford" and get a result displayed in chrome.

Using FireBug, I can see that I am returning valid JSON result, but get a 'TypeError: e is undefined' error message.

http://jsfiddle.net/franH/znkV3/14/

var app = new kendo.mobile.Application(document.body, {

transition: 'slide'
});

$(document).ready(function() {
$("#autoComplete").kendoAutoComplete({
    minLength: 7,
    dataTextField: "title",
    filter: "contains",
    placeholder: "Select town...",
    animation: {
        open: {
            effects: "fadeIn",
            duration: 2000,
            show: true
        }
    },

    close: function(e) {
        var str1 = "Dropdown Item Selected:" + " " + e.item;
        alert(str1);
    },
    dataSource: new kendo.data.DataSource({
        transport: {
            read: {
                url: "http://api.geonames.org/wikipediaSearchJSON",
                data: {
                    q: function() {
                        return $("#autoComplete").data("kendoAutoComplete").value();
                    },
                    maxRows: 10,
                    username: "pete"

                }
            }
        },
        schema: {
            data: "geonames"
        }
    }),
    change: function() {
        this.dataSource.read();
    }
    })
});
fran
  • 437
  • 1
  • 5
  • 14

3 Answers3

1

The only problem I see is that there is no such thing as e.item for the close event. Use the value method to get the value of the autocomplete.

Atanas Korchev
  • 30,562
  • 8
  • 59
  • 93
1

Hello you are requesting json from another domein which is not allowed by the Same origin policy. However by default Chrome does not care about this and this is why it still works.

Since you cannot force Users to change their browsers settings I would suggest you to search for a jsonp endpoint or another service which supports it.

Community
  • 1
  • 1
Petur Subev
  • 19,983
  • 3
  • 52
  • 68
0

Got it working in FireFox by adding the line

datatype: "jsonp",

Updated the example fiddle: http://jsfiddle.net/franH/znkV3/15/

var app = new kendo.mobile.Application(document.body, {
  transition: 'slide'
});

$(document).ready(function() {
  $("#autoComplete").kendoAutoComplete({
    minLength: 7,
    dataTextField: "title",
    filter: "contains",
    placeholder: "Select town...",
    animation: {
        open: {
            effects: "fadeIn",
            duration: 2000,
            show: true
        }
    },

    close: function(e) {
        var str1 = "Dropdown Item Selected:" + " " + e.item;
        alert(str1);
    },
    dataSource: new kendo.data.DataSource({
        transport: {
            read: {
                url: "http://api.geonames.org/wikipediaSearchJSON",
                dataType: "jsonp",
                data: {
                    q: function() {
                        return $("#autoComplete").data("kendoAutoComplete").value();
                    },
                    maxRows: 10,
                    username: "pete"

                }
            }
        },
        schema: {
            data: "geonames"
        }
    }),
    change: function() {
        this.dataSource.read();
    }
  })
});
CodingWithSpike
  • 42,906
  • 18
  • 101
  • 138
fran
  • 437
  • 1
  • 5
  • 14