-1

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.

Jongware
  • 22,200
  • 8
  • 54
  • 100
Dmitri
  • 53
  • 1
  • 7
  • Stuff like as follows just isn't working! : $("#response_html").change(function() { setTimeout(function(){alert("[[!GetField? &docId=`3` field=`basket`]]");}, 1000); }); – Dmitri Dec 17 '17 at 13:05

1 Answers1

1

I found an answer. Another empty-template ajax resource had to be created with snippet call in its contents (pdoTools extension is needed to make the snippet use javascript values, i.e.[[!custom_snippet? &post_var1 = [[!#POST.javascript_var1]]]]), as well as a $.post call from chunk to this ajax resource performed. This is because snippets in chunk gets processed before chunk is displayed, and cannot be processed after.

Dmitri
  • 53
  • 1
  • 7