Simple ajax search on discogs

Proof of concept for real-time song-searching

by jaap

HTML

<input type="text" placeholder="song" id="query" value="kleine jongen">
<button id="button">Search</button>
<ul id="songs"></ul>

JavaScript

$(document).ready(function () {
    $("#query").bind('keydown keypress', function () {
        setTimeout(function () {
            var q = $("#query").val();
            $.getJSON("http://api.discogs.com/database/search?type=master&q=" + q + "&page=1&per_page=10", function (data) {
                console.log(data);
                $('#songs').empty();
                $.each(data.results, function () {
                    $('#songs').append("<li><img width=20 height=20 src='" + this.thumb + "' /> " + this.title + "</li>");
                });

            });
        }, 1000);
    });


});