Can't POST variables with jquery/ajax
<p>I have an XML file that changes every few seconds. I would like to saw the data in a div (with the help of jQuery/ajax). I manage to make data autoreload with the help of <code>simplexml_load_string</code>, but because the reload is happening only in a div, I can't use PHP commands like $_POST to keep and the old data between reloads. I would like to have a very simple example of code that takes a variable between ajax div reloads. I try this so far but it is not working. </p>

<p><strong>First try</strong><br>
html file:</p>

<pre><code>&lt;script src="jQuery_v2.1.1.js" type="text/javascript"&gt;test&lt;/script&gt;

&lt;script&gt;    
$(document).ready(function(){
    setInterval(function(){
        $("#screen").load('phpcode.php')
    }, 5000);

    $.ajax({
        type: 'POST',
        url: 'test.php',
        data: {'varcount': $varcount}
    });
});
&lt;/script&gt;
&lt;div id="screen"&gt;&lt;/div&gt;
</code></pre>

<p>phpcode.php</p>

<pre><code>&lt;div&gt;
&lt;?php
    $varcount = $_POST['varcount'];
    $varcount += 1;
    echo  "Test ".$varcount."&lt;br&gt;";
?&gt;
&lt;/div&gt;
</code></pre>

<p><strong>Second try</strong> (I tryed to convert javascript variable to PHP so that i can POST it, and then convert it again to  javascript so that i can sent it back via jquery/ajax). <br></p>

<p>test.php:</p>

<pre><code>&lt;script src="jQuery_v2.1.1.js" type="text/javascript"&gt;test&lt;/script&gt;
&lt;script&gt;    
$(document).ready(function(){
    setInterval(function(){
        $("#screen").load('phpcode.php')
    }, 5000);
    $.post("test.php", { varcount: varcount } );        
});
&lt;/script&gt;
&lt;div id="screen"&gt;&lt;/div&gt;
</code></pre>

<p>phpcode.php</p>

<pre><code>&lt;div&gt;
&lt;?php
    $varcount = $_POST['varcount'];   
    $varcount += 1;
    echo  "Test ".$varcount."&lt;br&gt;";
?&gt;
&lt;script&gt;
    var varcount = &lt;?php echo "$varcount"; ?&gt;    // convet it to javascript variable
&lt;/script&gt;
&lt;/div&gt;
</code></pre>

<p>Questions are: <br>
1. <em>What is wrong in the above code/s and I can't POST any variable?</em> <br>
2. <em>Because XML file is very big (120kb) and reloads every few seconds might be problem for the server, is there any better way to do it?</em> <br>
3. <em>I will have to POST many different array in my final code. How would be able to POST 2 different arrays?</em> <br></p>

<p>Thanks in advance. Any help would be appreciated. </p>