JSFiddle - React, Tailwind, and code Playground

by guest271314

HTML

<button id="error">error</button>
<button id="success">success</button>

JavaScript

$(function() {
    var urls = ["/echo/jsons/", "/echo/json/"];
    var file = JSON.stringify({"abc" : 123});
    var request = function (url) {
        return $.ajax({
        url : url, 
        type : "POST",
        data : {json : file},
        statusCode : {
            200 : function (data, textStatus, jqxhr) {
                    alert(JSON.stringify(data.abc));
            },
            403 : function (jqxhr, textStatus, errorThrown) {
                    alert(textStatus + "\n" + errorThrown);
            },
            404 : function (jqxhr, textStatus, errorThrown) {
                    alert(textStatus + "\n" + errorThrown);
            }
        }
    });
    };
    $("button#error").on("click", function(e) {
        request(urls[0]);
    });
    $("button#success").on("click", function(e) {
        request(urls[1]);
    });

    
});