I have a chunk in resource id 3 which does a $.post call to an ajax empty-template resource id 1, which contains in its contents a snippet call which assigns a value to a TV id 2 in resource id 3 and then successfully (!) displays it right away:
$id_resource = $modx->getObject('modResource', 3);
$id_tv = 2;
$value = serialize($items);
$tv = $modx->getObject('modTemplateVar',array('id'=>$id_tv));
$tv -> setValue($id_resource, $value);
$tv->save();
$res = $modx->getObject('modResource',array('id'=>$id_resource));
echo $res->getTVValue($id_tv);
But when I try to create a setTimeout alert in the same chunk with [[*name_of_tv_id_2]] 1 second after, I get nothing. And nothing works to get that TV value, which seems to have set successfully in the ajax call. I tried a snippet [[!getTV]] too with
$id_resource = $modx->getObject('modResource', 3);
$id_tv = 2;
$res = $modx->getObject('modResource',array('id'=>$id_resource));
echo $res->getTVValue($id_tv);
but nothing. Any ideas of what am I doing wrong? Thanks in advance.