【问题标题】:Cant access spotify object无法访问 Spotify 对象
【发布时间】:2015-03-15 17:40:58
【问题描述】:

我想显示从我的 api 控制器传递的艺术家的专辑 请求是here。 我可以访问 info 对象,但是当我访问相册对象时,它返回 undefined

<script>
$(function () {
    $('table tr').click(function () {
        var id = this.id;
        $.ajax({
            type: "GET",
            url: '/api/author/GetName/' + id,
            contentType: "text/plain charset-utf-8",
            data: id,
            dataType: "json",
            success: function (data) {
                getDetails(data.name);

            }
        });
        }

    );
});//End ready
function getDetails(art) {
    $.ajax({
        type: "GET",
        url: 'http://ws.spotify.com/search/1/track.json?q='+ art ,
        dataType: 'json',
        success: function (data) {

            $('#summaryDisplay').empty();
            $('#summaryDisplay').append((JSON.stringify(data.albums)) + '<br/>');

            alert(JSON.stringify(data.info));
        },
        error: function (data) {
            $('#summaryDisplay').html('<h3>Error in retrieval</h3>');
        }
    });
}

【问题讨论】:

    标签: ajax asp.net-mvc api spotify


    【解决方案1】:

    您在代码中访问了错误的 URL。使用album 而不是track

    {
        // [...]
        url: 'http://ws.spotify.com/search/1/album.json?q='+ art,
        // [...]
    }
    

    【讨论】:

    • 对不起,当我整理这里的代码时,我必须按回太多次,这本来是专辑,我是否必须循环遍历对象,因为有多个?仍然出现未定义
    • 只有从 track 更改为 album 对我有用。看到这个fiddle
    • 看来我必须循环播放,谢谢你的回复
    猜你喜欢
    • 2017-05-23
    • 2013-05-03
    • 2019-10-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多