Why isn't string getting passed into function - jQuery
<p>First, I grab HTML using jQuery's $.ajax function. </p>

<p>In the success function I alert it (this works correctly and shows an HTML string as expected);</p>

<p>Then I pass it in as a variable to another function, processHTML. But it's not working and says the variable is null. I confirm this with an alert.</p>

<pre><code>var my = my || {};

jQuery(function ($) {
  my.html = {
    getHTML: function(url) {
      $.ajax({
        url: url,
        dataType: "html",
        success: function( myHTML ) {
          alert(myHTML); // shows string, as expected
          my.html.processHTML(myHTML); //returns null
        }
       });
    },

    processHTML: function ( myHTML ) {
      alert(myHTML);
      // do stuff and return myHTML
    }

  } // end of my.html object
}); // end of jQuery wrapper function
</code></pre>

<p>Why isn't the string getting passed from the success callback into the processHTML function? If I replace myHTML in the success callback with an actual string (<code>&lt;div&gt;test&lt;/div&gt;</code>), that gets successfully passed into the function.</p>

<hr>

<p><strong>Update:</strong> Here's the actual code, as requested.  It is invoked by clicking a link with <code>onclick="hey.mydoc.ajax2({source: 'http://www.mysite.com/mypage'})"</code>. This is also on <a href="http://jsfiddle.net/supertrue/WMSZk/" rel="nofollow">JSFiddle</a> but I get <code>ReferenceError: Can't find variable: hey</code> when clicking the link, which doesn't happen on my site.</p>

<pre><code>var hey = hey || {};

jQuery(function ($) {

hey.mydoc = {

        //////////////////////////////////////////////////////
        //////////////////////////////////////////////////////
        //////////////////////////////////////////////////////
        getHTML: function ( source ) {

                  $.ajax({
                      url: source,
                      dataType: "html",
                      beforeSend: function(){ 
                        },
                      success: function( myHTML ) {
                        alert('myHTML is '+myHTML );
                        hey.mydoc.processHTML( myHTML );
                      } // end of success function
                  });
        }, // end of method


        //////////////////////////////////////////////////////
        //////////////////////////////////////////////////////
        processHTML: function ( myHTML ) {

        alert ('processHTML - ' + myHTML );
             myHTML = $(myHTML);
            myHTML.find('script').remove();
            // and a bunch of other DOM manipulations...

           var content = "&lt;!DOCTYPE html&gt;&lt;html&gt;" +  myHTML.html() + "&lt;/html&gt;";
           return content;
        }, // end of method


    //////////////////////////////////////////////////////
    //////////////////////////////////////////////////////
    ajax2: function ( options ){


        $.ajax({
                  url: options.content,
                  dataType: "html",
                  success: function( myHTML ) {
                    alert('myHTML is '+myHTML ); // myHTML is string of html, as expected
                    var newHTML = hey.mydoc.processHTML( myHTML );  // myHTML not getting passed in
                    alert(newHTML);

                  } // end of success function
              });
        } // end of method
   } // end of hey.mydoc namespace


}); //end of jQuery wrapper
</code></pre>
