用jsonp ajax读取文件

时间:2013-11-26 15:41:14

标签: jquery ajax jsonp

我试图从json文件中获取数据,但它无法返回任何内容。我对此非常陌生。这是fiddle

$.ajax({
type: 'GET',
url: 'http://sunrise.bluechipholidays.co.uk/webservices/property/availability/apikey/demo/propertycode/ha01/date/2012-05-01/nights/5/echo/html',
dataType: 'jsonp',
success: function(json) {
    var result = '<h3>' + json.bookable + '</h3>' +
                 '<p>Languages: ' + json.price + '</p>' +
                 '<p>Followers: ' + json.available + '</p>';
    $('#test').append(result);
}
});

非常感谢!

1 个答案:

答案 0 :(得分:0)

尝试

<input class="datepicker" />
<div id="test"></div>

然后

$('.datepicker').datepicker({
    onSelect: function (date) {
        $.ajax({
            type: 'GET',
            url: 'http://sunrise.bluechipholidays.co.uk/webservices/property/availability/apikey/demo/propertycode/ha01/date/' + $.datepicker.formatDate("yy-mm-dd", $(this).datepicker('getDate')) + '/nights/5/echo/html',
            success: function (json) {
                $.each(json.data, function (_, json) {
                    var result = ' <h3> ' + json.bookable + ' </h3>' +
                        '<p>Languages: ' + json.price + '</p> ' +
                        ' <p> Followers: ' + json.available + ' </p>';
                    $('#test').html(result);
                });
            }
        });
    }
});

演示:Fiddle