JSFiddle - React, Tailwind, and code Playground

by supertrue

HTML

<a href="#" onclick="hey.mydoc.ajax2({content: 'http://fiddle.jshell.net/'});">Test AJAX call</a>

JavaScript

var hey = hey || {};

jQuery(function ($) {

hey.mydoc = {
     //////////////////////////////////////////////////////
     //////////////////////////////////////////////////////
     processHTML: function ( myHTML ) {

            // make sure the HTML is there
            alert('This HTML was passed into processHTML():'+myHTML);
            
            // put the html in a jquery wrapper
            myHTML = $(myHTML);
            
            // test it out
            alert(myHTML.html()); // doesn't work! returns null
            
            // manipulate stuff with jQuery and return a string
            myHTML.find('script').remove();
            myHTML = "<!DOCTYPE html><html>" +  myHTML.html() + "</html>";
            return myHTML;
            
     }, // end of method
        
    //////////////////////////////////////////////////////
    //////////////////////////////////////////////////////
    ajax2: function ( options ){        

        $.ajax({
                  url: options.content,
                  dataType: "html",
                  success: function( myHTML ) {
                     var newHTML = hey.mydoc.processHTML( myHTML );
                     alert('The output of the ajax success callback: '+newHTML);
                  } // end of success function
              });
        
     } // end of method

} // end of hey.mydoc namespace

});