Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/89.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript API获取请求_Javascript_Jquery_Spotify - Fatal编程技术网

Javascript API获取请求

Javascript API获取请求,javascript,jquery,spotify,Javascript,Jquery,Spotify,我不熟悉编码,所以这可能是一个简单的修复方法,但我不确定我做错了什么。我正在构建一个使用 我不想撒谎,这不是一个超级有用的程序哈哈,但是你要做的是为艺术家输入一个ID值,我希望它返回所有专辑的列表。下面是一个id示例:4P0dddbxPil35MNN9G2MEX 这是我收到的错误消息: (请求错误) 有人知道为什么我的搜索结果显示为“未定义”吗 以下是我的JavaScript/jQuery: var showArtistInformation = function(artistSelect){

我不熟悉编码,所以这可能是一个简单的修复方法,但我不确定我做错了什么。我正在构建一个使用

我不想撒谎,这不是一个超级有用的程序哈哈,但是你要做的是为艺术家输入一个ID值,我希望它返回所有专辑的列表。下面是一个id示例:
4P0dddbxPil35MNN9G2MEX

这是我收到的错误消息:

(请求错误)

有人知道为什么我的搜索结果显示为“未定义”吗

以下是我的JavaScript/jQuery:

var showArtistInformation = function(artistSelect){
    //clone the result template
    var artistResult = $('.searchResults .hiddenTemplates .artistAlbumInformation').clone();
    //Set the name of the artist in the result
    var theArtistName = result.find('.artistName');
    theArtistName.text(artists.name);
    //Get the name of the artist Album
    var theAlbumName = result.find('albumName');
    theAlbumName.text(album.name);
    //Get the genre of the album
    var theAlbumGenre = result.find('albumGenre');
    theAlbumGenre.text(genre.name);
    //Get the tracklisting for each Album
    var theTrackNames = result.find('trackList');
    theTrackNames.text(track.name);

    return artistResult;
}

    var getArtistAlbumInformation = function(artistID){
        //the parameters that we need to pass in our request to Spotify's API
        var request = {
            album_type: "album"
        };

        $.ajax({
            url: "https://api.spotify.com/v1/artists/" + artistID + "/albums",
            data: request,
            dataType: "jsonp",
            type: "GET",
        })
        //What the function should do if successful
        .done(function(result){
            $.each(result.items, function(i,item){
                var artistReturnedResult = showArtistInformation(item);
                $('.artistAlbumInformation').append(artistSelect);

            })

        })
        //What the function should do if it fails
        .fail(function(jqXHR, error){
            var errorElem = showError(error);
            $('.search-results').append(errorElem);
        });


    }

//Clicking the submit button activates the function that gets the results
$(document).ready(function() {

    /*Clicking the Search Button*/
        $('.searchButton').on('click',function(event){
            event.preventDefault();
            //Zero out results if previous results have run
                $('.albumArtistInformation').html('');
            //End User Input
            var userSearch = $(this).find("input[name='musicalArtist']").val();
            getArtistAlbumInformation(userSearch);


        });



})

https://api.spotify.com/v1/artists/
未定义
/albums?callback=jquery1110414943396958709\u 1449799723013&album\u type=album&\u=144979972301400

我的。您正在为函数提供的艺术家ID未定义。这意味着无论从何处调用此函数,都是错误所在。尝试
console.log(artistID)在您的代码中,您可以自己查看它

var userSearch=$(this.find)(“输入[name='musicalArtist']”)val()是您的问题所在

您正在使用
$(this)
进行选择,在单击功能的上下文中,它是实际的搜索按钮。因此,您试图在按钮内找到
musicalArtist
,这毫无意义

请尝试使用此选项:

var userSearch = $("input[name='musicalArtist']").val();

只需确保没有多个具有该名称的输入,因为选择器可能返回多个元素。

将jQuery查找更改为:

var userSearch = $("input[name='musicalArtist']").val();

指的是触发单击事件的按钮。

如果要获取唱片集id,需要使用url,如果要获取艺人信息,请立即使用url。您正在定义未定义的艺人,然后将唱片集放在后面,此外,我已尝试将此id用于这两个项目,但此id无效,因此您需要在此处找到正确的id。这是一个有效的url,要查找相册,请单击此链接,您将看到有效的响应

检查url。您正在请求`/artists/UNDEFINED/相册。这意味着artistID在计算时为空。您在哪里调用getArtistAlbumInformation方法?显示代码拒绝执行脚本,因为其MIME类型('application/json')不可执行,并且启用了严格的MIME类型检查。这就是我收到的错误信息。啊哈,看来你原来的问题已经解决了,你已经进入下一个问题。这里有更多信息:
dataType:“jsonp”,
是您的问题。在这种情况下,您需要
dataType:“json”,
Awesome,我的问题已经解决了。我有另一个错误消息,但我想我可以处理这部分。这会让我玩一会儿。谢谢你们的帮助,伙计们!拒绝执行脚本,因为其MIME类型(“应用程序/json”)不可执行,并且启用了严格的MIME类型检查。这就是我收到的错误消息。如果您将数据类型更改为:
datatype:“json”
(而不是
jsonp
),它会工作。我收到了另一条错误消息,但我想我能找出那部分。谢谢你们的帮助,伙计们!如果你点击你发布的最后一个链接,他们有“相册类型”而不是“类型”,那么你确定吗?我对这些东西很陌生,我只是好奇。我的错是我只是很快地阅读了文档,结果发现album_type=album是一个有效的参数,这是他们说的第一个参数,我一定读过了。很抱歉,我将从我的答案中删除,类型是一个有效的参数,也是他们最后声明的参数之一。但是你需要在url的开头定义艺术家或专辑,如果在你的示例中它说未定义,那么id将转到这里。你现在说的是,它只搜索专辑id值,而不是使用艺术家id值,目前的情况如何?是的,我看到您正在尝试获取艺术家专辑,如果您已正确插入艺术家id,您现在应该会得到有效的响应。这里是一个随机艺术家的url响应,它与您希望的内容一致。在本文档中,我已经阅读了您的原始内容问题错误现在您有了正确的id,您是否得到了有效的答复?还是还有问题