Projektarbeit jQuery Mobile

07.02.2017 08:28 Uhr

In der heutigen Sitzung wird die Projektarbeit besprochen und teilweise bereits bearbeitet. 

<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="https://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.css">
    <script src="https://code.jquery.com/jquery-1.11.3.min.js"></script>
    <script src="https://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.js"></script>
</head>
<body>

<div data-role="page" id="page-search">

    <div data-role="header">
        <h1>Suche</h1>
    </div>

    <div role="main" class="ui-content">
        <form>
            <label for="txt-search">Suchtext:</label>
            <input name="search" id="txt-search" type="text" value="">
            <button type="button" class="ui-btn" id="btn-search">Jetzt suchen</button>
        </form>
    </div>

    <div data-role="footer">
        <h4>Footer</h4>
    </div>

</div>


<div data-role="page" id="page-list">

    <div data-role="header">
        <h1>Liste</h1>
    </div>

    <div role="main" class="ui-content">

        <ul data-role="listview" data-inset="true" id="list-books">
            <li><a href="#">Buch1</a></li>
            <li><a href="#">Buch2</a></li>
            <li><a href="#">Buch3</a></li>
        </ul>

    </div>

    <div data-role="footer">
        <h4>Footer</h4>
    </div>

</div>




<script>

    $(document).ready( function() {


        $('#btn-search').click(function() {

            $('#list-books').empty()

            var myField = $('#txt-search').val();
            var myUrl = 'https://www.googleapis.com/books/v1/volumes?q=' + myField;

            $.ajax({
                url: myUrl,
                method: 'GET',
                dataType: 'json'
            }).done(function(data){

                var txtUl = "";

                for( var i = 0; i < data.items.length; i++) {

                    txtUl =
                        txtUl
                        + '<li><a href="#">'
                        + data.items[i].volumeInfo.title
                        + '</a></li>';

                    console.log( data.items[i].volumeInfo.title );
                    console.log( data.items[i].volumeInfo.subtitle );
                    console.log( data.items[i].volumeInfo.description );

                }

                $('#list-books').html(txtUl);

                $.mobile.changePage("#page-list");


            }).fail(function() {

                alert('fehler');
                console.log('fehler');

            });



        });




    });


</script>


</body>
</html>