Sunday, May 10, 2020

factor of duh - reading JSON post data

Heh. So I realized one of the reasons I shanked that tech take home, besides the weirdness of JS date transform is I had a one letter type (header not headers) in the JSON fetch code I used. I really should have sucked it up and used jQuery or some such. Talk about premature optimization...

But I stumbled over that when realizing I was behind the curve in my "use PHP for JSON endpoints... to read a JSON post, you can't rely on $_POST, you need something like:
 $POSTJSON = json_decode(file_get_contents('php://input'),true);
which will then be the associative array you might expect...

No comments:

Post a Comment