JSFiddle - React, Tailwind, and code Playground

by nogoodatcoding

HTML

<input type="submit" id="go" name="go" value="Go" />
<br />
<iframe id="errorFrame" height="50%" width="85%"/>

JavaScript

$(document).ready(function(){
        console.log("Loaded");
        alert("Loaded");
        
        //$('#errorFrame').hide();
        $("#go").click(function(e){
            console.log("Logging");
            $.ajax({
                success: function(data, responseText){ 
                    console.log(data, responseText);
                    loadFrame('errorFrame', data);
                }, 
                error: function(data, responseText){
                    console.log(data.responseText, "error");
                    loadFrame('errorFrame', data.responseText);
                }
            });
    });
});

/**
* Code credit: http://www.tek-tips.com/viewthread.cfm?qid=1021687
*/
function loadFrame(frameId, text){
    var ifrm = document.getElementById(frameId);
    ifrm = (ifrm.contentWindow) ? ifrm.contentWindow : (ifrm.contentDocument.document) ? ifrm.contentDocument.document : ifrm.contentDocument;
    ifrm.document.open();
    ifrm.document.write(text);
    ifrm.document.close();
}