I'm doing some tests in Magento using AJAX and I'm having the following problem: I want to output periodically some content I've been generating on my php script on my actual page.
So when I click on a Button my js function in my page is called:
page.phtml:
function requestLoop(){
var url = '<?php echo $this->getUrl('mymodule/index/readLine') ?>';
new Ajax.PeriodicalUpdater('Output',url,{
method: 'post',
insertion: 'after',
frequency: 3,
decay: 2
});
}
where 'output' is the ID of my table where I want to output my content. This AJAX request calls my separate php controller file:
$private static $i=0;
public function readLineAction(){
self::$i+= 2;
$this->getResponse()->setBody(Mage::helper('core')->jsonEncode(self::$i));
$this->getResponse()->setHeader('Content-type','application-json');
}
Now I would expect that my
Table displays the numbers 2 4 6 8 ....
But instead I only get 2 2 2 2 ....
So there must be something wrong with either my Request oder my Variable $i. Can anyone give me an advise?
Thanks in advance