JSFiddle - React, Tailwind, and code Playground

by Eric Howe

HTML

<button>click</button>

JavaScript

var data = null;

$('button').click(function() {
    var _this = this;
    console.log('clicked');
    $.ajax({
        type: 'post',
        url: '/echo/json/',
        data: {
            delay: 1,
            json: '[1,2,3,4,5,6]'
        },
        success: function(json) {
            data = json;
            $(_this).trigger('data-loaded');
        }
    });
});

$('button').on('data-loaded', function() {
    console.log('data is here: ', data);
});