On March 26, 2019 we launched new MODX Forums. Please join us at the new MODX Community Forums.
Subscribe: RSS
  • Hi All,

    I've recently updated my site to 1.0.9 and put the hot fix in place. I've noticed that one of my pages which uses AJAX and JSON has stopped working.

    It's been difficult to debug and there is little information from modx but it seems as the json_decode isn't performing what is needed. I can only put this down to the site update as I haven't change the code in some time.

    I've checked my JSON code with an online parser and everything is fine however the foreach loop against each json item just fails against "undefined property".

    Would anyone be able to help with this?

    • If you are posting JSON strings, please translate the following hexadecimal entity encoded signs ('[', ']', '{', '}') back to the not encoded ones before decoding the JSON. In one of the next releases a jsonDecode MODX API function should cover that. [ed. note: Jako last edited this post 7 years, 2 months ago.]
      • Thanks for replying Jako. I haven't had much time to track it down but I've nailed it.

        I had to wrap my command in html_entity_decode!!! Even though it looked ok in FF Chrome showed the way on what was being sent.

        $data = json_decode(html_entity_decode(stripslashes($_POST['data'])));

        • In 1.0.10 you could use $modx->jsonDecode($json, $assoc) for that.

          Sorry for that change, but entity encoding of MODX tags seems the best way for me to get rid of the hassles with displaying not stripped MODX tags from GPC for several reasons.

          $modx->stripTags don't remove half MODX tags like in '[[Ditto &parents=`0` &test=`' and that could cause issues if this string is displayed followed by a second output with half closing tags like in '`]]'. MODX tags could be divided by i.e. html tags like in '[<b>[Ditto? &parents=`0` &test=`' and if those html tags are stripped by $modx->stripTags a valid half MODX tag is displayed.

          Those entity encoded MODX tags are safe for most cases, they only cause that issue that you have discovered by posting JSON strings.
          • Thanks Jako.

            I can understand that. I'm just glad I found it to correct it. I'll try and remember about the command when 1.0.10 is released.