We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 15001
    • 697 Posts
    Hi,

    I encounter a very strange problem with some jQuery $post() request targeting a snippet located in one document. The snippet itself calls another snippet through $modx->runSnippet().
    That second snippet outputs a language code like ’fr’, ’en’, a.s.o.

    $lbparams['root'] = '123';
    $lbparams['service'] = 'get_language';
    
    //$lc=$modx->runSnippet('GetDocLanguage',$lbparams);
    $lc='fr';
    
    switch ($lc) {
      case 'en' : $to_cart = "Add to cart";break;
      case 'de' : $to_cart =  "Zum Korb";break;
      default: $to_cart = "Au panier";
      }
    echo $to_cart;


    In code above, if I activate the $modx->runSnippet() line, I get this error in Firebug and the Javascript of my page doesn’t work anymore. This occurs also if $lc=’fr’ is set statically after the snippet is through $modx->runSnippet().
    syntax error
    [Break on this error] ()

    However, the correct string is outputed at the end of the main snippet.

    If I disable the $modx->runSnippet() line, all works fine, but I loose the possiblity to change the $to_cart variable dynamically.

    As the snippet sends its output by "echo", I assume that this strings is transmitted outside of the snippet and corrupts the answer to the ajax call. I tried using "return" instead of echo, but it fails completely.

    Does someone have any idea what’s going wrong ?