Re-using a variable inside jquery.ajax
<p>I have the following function. This function is called with a setTimeout upon a form submit. </p>

<pre><code>function get_progress( fileID, filename) {
$.ajax({
    url: filename,
    type: 'HEAD',
    success: function() {
        $.ajax({
            type: 'POST',
            url: 'read_file.php',
            data: 'filename=' +filename,
            success: function(html) {
                document.getElementById(fileID).innerHTML = html + ' &lt;img src="images/loading.gif" /&gt;'
                setInterval("get_progress(fileID,filename)",400);
            }
        });
    }
});}
</code></pre>

<p>I am running into errors as soon as the setInterval is triggered upon success. It appears that fileID and filename are <strong><em>empty variables</em></strong>, despite having values in them before the code reaches the success state. </p>

<p>Why is this happening ? Do I have to assign them as global variables instead ?  </p>
