Echoing <script> from PHP to jQuery AJAX causes problems with my interval
<p>Basically, I'm grabbing contents from a PHP file. I check it every 5 seconds. If the content differs from the content on the page, it loads that new content:</p>

<pre><code>    &lt;script type="text/javascript"&gt;
    $(document).ready(function()
    {
        $.ajaxSetup ({ cache: false });  

        var loadUrl = "&lt;?php echo site_url("admin/get_uploads"); ?&gt;";  

        $("#result").load(loadUrl);

        var refreshId = setInterval(function() {
            $.get(loadUrl,function(result){
                if(result !=  $("#result").html())
                {
                    $("#result").html(result);
                    $("#result").effect("highlight", {}, 2000);
                }
            });
        }, 2000);
    });  
    &lt;/script&gt;
</code></pre>

<p>My PHP is as follows:</p>

<pre><code>    function get_uploads()
    {
        $this-&gt;db-&gt;order_by('upload_date', 'desc');
        $uploads = $this-&gt;je_model-&gt;get_uploads(array('new' =&gt; TRUE));

        echo '&lt;script&gt;function delete_upload(id){$.ajax({type: "POST",url: "'.site_url("admin/delete_upload").'/" + id,success: function(html){$("#" + id).hide();}});}&lt;/script&gt;';

        if ($uploads == NULL):
            echo 'NO NEW UPLOADS';
        else:
            foreach ($uploads as $row):
                echo '&lt;p id="'.$row-&gt;id.'"&gt;'.$row-&gt;file.' '.anchor('admin/file/'.$row-&gt;id.'/complete', 'Complete', 'title="Complete"').' '.anchor('#', 'Delete', 'title="Delete File" onclick="delete_upload('.$row-&gt;id.'); return false"').'&lt;/p&gt;';
            endforeach;
        endif;
    }
</code></pre>

<p>I'm echo'ing the  tag. With the script tag in there, my #result DIV constantly re-loads. For some reason, the Javascript is thinking there's a difference between the content when there shouldn't be. When I remove the  tag from my PHP, it works as it should. It only updates if there are new uploads.</p>

<p>Any ideas what's wrong here?</p>
