JSFiddle - React, Tailwind, and code Playground

by Antonin Loury

JavaScript

var data = {
        json: JSON.stringify({
            text: 'Echo JSON'
        })
    }

    $(document).ajaxSuccess(function (event, xhr, settings) {
        console.log('Global ok');
        console.log(settings.custom);
    });

    function makeRequest() {
        var req = $.ajax({
            //post the request to /echo/json/ and specify the correct datatype
            url: '/echo/json/',
            dataType: 'json',
            data: data,
            success: function (data) {
                //you get back exactly what you sent in the json 
                console.log(data.text);
            },
            type: 'POST',
            custom: 'YEAHHH'
        });
        return req;
    };

    makeRequest().then(function () {
        console.log('ok');
    }, pasOk);

    function pasOk() {
        console.log('pas cool');
    }