使用JSON显示图像

时间:2014-05-30 15:13:13

标签: json image

我试图学习如何使用JSON,但我被卡住了。 现在我想在点击图像时显示图像。 我觉得我很接近,但不知道出了什么问题。 此外,这是使用JSON显示图像的正确方法吗? ("

HTML:

<nav>
            <ul>
                <li><a id="boek1" href="#">Boek 1</a></li>
                <li><a id="boek2" href="#">Boek 2</a></li>
            </ul>
</nav>

脚本:

   $(document).ready( function()
    {
        $('#boek1').click(function(event)
        {
            event.preventDefault();

            $.ajax(
            {
                url:        'Booklist.json',
                dataType:   'json',
                success:    function(data)
                {   
                    $('#content').append('<img src="'data.books.cover[0].source'">');
                    console.log(item);
                },
                error: function()
                {
                    alert("Houston, we have a problem");
                }   
            });             
        });
    });

JSON:

{
    "books": [
        {
            "title": "HTML5 Media, Integrating audio and video with the Web",
            "author": "Shelley Powers",
            "desc": "A detailed introduction to presenting audio and video in HTML5, from markup through scripting. It will explain not just placing content in pages but interaction through Javascript APIs, to build media players that could be used cross-browser.",
            "publishDate": "July 2011",
            "url": "http://oreilly.com/catalog/0636920019824/",
            "cover": [
                {
                    "type": "bigCover",
                    "source": "img/cat_005.gif",
                    "alternative": "HTML5 Media"
                },
                {
                    "type": "cover",
                    "source": "img/bkt_005.gif"
                }
            ]
        },
        {
            "title": "HTML5: Up and Running",
            "author": "Mark Pilgrim",
            "desc": "If you don't know about the new features available in HTML5, now's the time to find out. This book provides practical information about how and why the latest version of this markup language will significantly change the way you develop for the Web. HTML5: Up & Running carefully guides you though the important changes in this version with lots of hands-on examples, including markup, graphics, and screenshots. You'll learn how to use HTML5 markup to add video, offline capabilities, and more -- and youÕll be able to put that functionality to work right away.",
            "publishDate": "August 2010",
            "url": "http://oreilly.com/catalog/9780596806033/",
            "cover": [
                {
                    "type": "bigCover",
                    "source": "img/cat_noCover.gif",
                    "alternative": "HTML5 Up and Running"
                },
                {
                    "type": "cover",
                    "source": "img/bkt_noCover.gif"
                }
            ]
        }
    ]
}

0 个答案:

没有答案