jQuery UI自动完成不是从http://ws.geonames.org/加载数据



访问我的小提琴

来自http://ws.geonames.org/searchjson?&; amp; country=de的数据不加载,如果我将其更改为http://www.geonames.org/searchjson?∁ compountry = de它说我需要一个用户名。

这是我正在使用的jQuery代码:

$(".city").autocomplete({
source: function (request, response) {
    $.ajax({
        url: "http://ws.geonames.org/searchJSON?&country=DE",
        dataType: "jsonp",
        data: {
            featureClass: "P",
            style: "full",
            maxRows: 12,
            name_startsWith: request.term,
            countryName: "Germany"
        },
        success: function (data) {
            response($.map(data.geonames, function (item) {
                return {
                    label: item.name + (item.adminName1 ? ", " + item.adminName1 : "") + ", " + item.countryName,
                    value: item.name
                }
            }));
        }
    });
}

});

有其他选择吗?

谢谢。

首先:您应该使用http://api.geonames.org/searchJSON?&country=DE代替http://ws.geonames.org/searchJSON?&country=DE后者用于高级Web服务,因此您需要一个帐户第二:http://api.geonames.org/searchJSON?q=DE&country=DE&lang=en&username=demo&callback=?您可以使用演示,但它的每小时限制为2000个查询(很多人共享),您可以创建一个免费帐户,但信用额度也有限。不确定您每天期望多少访问。

最新更新