开发者

why this jQuery response with "undefined"?

开发者 https://www.devze.com 2023-03-29 07:01 出处:网络
This jQuery code response with \"undefined\" why ?? function YouTube2() { $(document).ready(function(){ var txt=\"\";

This jQuery code response with "undefined" why ??

    function YouTube2()
    {
        $(document).ready(function(){
            var txt="";
            var url='https://gdata.youtube.com/feeds/api/videos?q=GoogleDevelopers&max-results=10&v=2&alt=jsonc';
            $.getJSON(url,function(json) {
                alert("ss");
                $.each(json.data.items, function(index, elem) {
                    alert(j开发者_高级运维son.data.items[index].thumbnail.default);
                });
             });
        });
     }
     YouTube2();


change default to sqDefault or hqDefault

http://sandbox.phpcode.eu/g/6aea7

        alert(json.data.items[index].thumbnail.Default);

to

        alert(json.data.items[index].thumbnail.sqDefault);

or to

        alert(json.data.items[index].thumbnail.hqDefault);


There is no default in the thumbnail object. There is sqDefault and hqDefault:

"thumbnail":{"sqDefault":"http://i.ytimg.com/vi/-kepYfCBg6w/default.jpg","hqDefault":"http://i.ytimg.com/vi/-kepYfCBg6w/hqdefault.jpg"}

Pick the one you want and use it :)


You are doing a cross domain request, something that you can't do because of the Same Origin Policy

0

精彩评论

暂无评论...
验证码 换一张
取 消