JSFiddle - React, Tailwind, and code Playground

by CR47

HTML

<div class="linklist">
    
</div>
<button id="mybutton">My l;aksjdf</button>

JavaScript

$('#mybutton').click(function() {
    $.ajax({
        url: 'http://polls.peopleenespanol.com/popular.json?score=flavored_likes&hours_ago=24&limit=20&section_name=likes&flavor=love&callback=renderRelatedHeadlines',
        type: 'get',
        //jsonp required for cross-site request
        dataType: 'jsonp',
        error: function (XMLHttpRequest, textStatus, errorThrown) {
            alert('get similar failed :(');
            console.log(JSON.stringify(XMLHttpRequest));
            console.log(JSON.stringify(textStatus));
            console.log(JSON.stringify(errorThrown));
        },
        success: function (data) {
            var popular_posts = {};
            var num = 0;
            $.each(data, function() { 
                $.each(this, function(key, value){
                    popular_posts[key + num] = value;
                    num++;
                });
            });
            var article_url1 = JSON.stringify(popular_posts.resource0.url);
            var title1 = JSON.stringify(popular_posts.resource0.name);
            var article_url2 = JSON.stringify(popular_posts.resource1.url);
            var title2 = JSON.stringify(popular_posts.resource1.name);
            var article_url3 = JSON.stringify(popular_posts.resource2.url);
            var title3 = JSON.stringify(popular_posts.resource2.name);
            $('.linklist').html('<ul><li><a href=' + article_url1 + ' class="trackReactRelated">' + title1 + '</a></li><li><a href=' + article_url2 + ' class="trackReactRelated">' + title2 + '</a></li><li><a href=' + article_url3 + ' class="trackReactRelated">' + title3 + '</a></li></ul>');
        }
    });
    
});