Live code following document ready in jquery
<p>I currently have a basic site to which I am loading content into via ajax on document ready. The problem is that this code is not "live" and requires me to re-include the php includes within the loaded page in order to access the queries contained within it.  </p>

<p>I know you can work around this by using the 'on' method when it comes to certain events so that the dynamically loaded code is functional from the start, but how would you go about it when the page has just loaded? It seems redundant and sloppy to have to reinclude my php includes on each loaded page. </p>

<p>Here's some code:</p>

<pre><code>&lt;?php
    session_start();
    require_once('dbconnect.php');
    require_once('functions.php');
?&gt;

&lt;!DOCTYPE html&gt;
&lt;html&gt;
    &lt;head&gt;
        &lt;script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"&gt;&lt;/script&gt;
        &lt;script type="text/javascript" src="x.js"&gt;&lt;/script&gt;
    &lt;/head&gt;
    &lt;body&gt;
        &lt;div id="container"&gt;
            &lt;div id="content"&gt;

            &lt;/div&gt;
        &lt;/div&gt;
    &lt;/body&gt;
&lt;/html&gt;
</code></pre>

<p>JS:</p>

<pre><code>$(document).ready(function() {
    $('#content').load('x.php', function() {
        alert("loaded");
    });
});
</code></pre>

<p>Loaded page:</p>

<pre><code>&lt;?php
    //LOAD ALL WORK
    $query = mysql_query("SELECT * FROM work");
    if (mysql_num_rows($query) &gt; 0) {
        while ($work = mysql_fetch_array($query)) {
?&gt;

&lt;div class="still_cell"&gt;
    &lt;img class="still_image" src="&lt;?php 
        print $work['image_path'];
    ?&gt;" /&gt;

    &lt;div class="still_info"&gt;
        Info
    &lt;/div&gt;
&lt;/div&gt;

&lt;?php   
        }
    }
?&gt;
</code></pre>

<p>Results in various php errors saying that the query produced no results unless I include the code to connect to the database nested in the loaded file</p>
