jQuery: Calling append() from within success function
<p>I am attempting to use jQuery to get the html contents of another page on the server and display it on the current page. Using an alert() function i can see the exact html that needs to be written, however, when i attempt to append, it causes some sort of error, and nothing is displayed at all when i load the page. I also tried to store the html to a variable and use document.write() to add it to the page, but found that the variable was empty... Any help would be greatly appreciated.</p>

<pre><code>&lt;script type="text/javascript"&gt;
   var totalPages = $("#hidden_navinfo .totalpages").text();
   var currentPage = $("#hidden_navinfo .startpage").text();
   var next = "";
   for ( var i = 1, len = totalPages; i &lt; len; i++)
   {
        var count = i+1;
        //$("#posts").load("/page/ .page");
        $.get(("/page/" + count), function(data) {
            var begin = data.indexOf("&lt;!--BEGIN POST DATA--&gt;")+22;
            var end = data.indexOf("&lt;!--END POST DATA--&gt;");
            next = data.substring(begin, end);
            alert(next); //displays the correct html
            $(".posts").append(next); //Causes nothing to be displayed
        });
        alert(next); //returns null
    }
&lt;/script&gt;
</code></pre>

<p>As far as im aware, this should add the text stored in "next" to the div of class="posts". The script is placed directly after this div.</p>

<p>What am i doing wrong?</p>

<p>(The html that is being extracted can be found here: <a href="http://www.trivialreviews.com/ext/sample.html" rel="nofollow">http://www.trivialreviews.com/ext/sample.html</a>)
(The page the script is called from can be found here: <a href="http://fuckmodernity.tumblr.com/tagged/series1/" rel="nofollow">http://fuckmodernity.tumblr.com/tagged/series1/</a>)</p>
