JSFiddle - React, Tailwind, and code Playground

HTML

<div id="response">loading</div>

JavaScript

function myFunction(callback) {
    $.ajax({
        type: 'POST',
        url: '/echo/json/',
        dataType: 'json',
        data: {
            json: JSON.stringify({
                'foo': 'bar'
            })
        }
    }).done(function(response) {
        callback(response);
    });
}

myFunction(function(response) {
    $('#response').html('response: ' + JSON.stringify(response));
});