AJAX

Uses Album API

by rlinares

HTML

<span class="button">Find</span>
<img id ="loading" src="http://www.milibrodecocina.es/img/loading.gif" style="display:none; width:30px;height:30px" />
<ul id="albums">
</ul>

CSS

body{
    background-color:blue;
}

.button
{
    background: blue;
    color: white;
    cursor: pointer;
}

JavaScript

$('.button').click(function() {
    $('#loading').show();
    $(this).hide();
    $.ajax({
        url: "http://api-v3.deezer.com/1.0/search/album/?q=folk&index=1&nb_items=10&output=json",
        success: function(json) {
            $('#loading').hide();
            console.log("Results: " + json.search.total_results);
            if (json.search.total_results > 0) {
                $.each(json.search.albums.album, function(index, item) {
                    $('ul').append('<li> <img src="' + item.image + '"/>' + item.name + '</li>');
                    
                    
                     $('input[type=checkbox]').click(function(event){ 
                   var selected = $('input[type=checkbox]:checked'); 
                   if(selected.length >2){ 
                       alert(''); 
                   }});
                });
                    
                    
                    
                    
                    $('li').hover(function(event){ 
                   $(this).css('background-color', 'Grey'); 
               }, function(){ 
                   $(this).css('background-color', '#FFFFFF'); 
               }); 
                    
               $('input[type=checkbox]').click(function(event){ 
                   var selected = $('input[type=checkbox]:checked'); 
                   if(selected.length >2){ 
                       alert(''); 
                   }});
                });
            }
            else {
                $('ul').append('<li>No results found</li>');
            }
        }
    }).error(function(xhr, ajaxOptions, thrownError) {
        $('#loading').hide();
        $(this).show();
        console.log("error:" + xhr.status);
    });
});