Gallery 3 Kohana and JSON posts
Expand Messages
· i_am_lord_beowulf
Message 1 of 4 , Nov 1, 2018
View Source
So I'm trying to break up my PHP module I'd designed to extract data from my photos using a third party website. The problem was that it took so long to perform the operation that PHP itself will time out, not to mention the fact that I have no status during the process. My initial plan when I got it working was to just create a Javascript monitor that would update as the status changed, but after a lot of the testing I've been doing the past couple of weeks, I'm not sure that would have worked either. At any rate, now I'm having to resort to passing all the working parameters back and forth between the Javascript and the PHP using JSON. That was a major challenge figuring out how Kohana handles posted parameters, but I finally got to the point that it's working the way it should. However, I'm now seeing a situation where it looks like Kohana is attempting to "prettify" the data coming in, so spaces and other characters are becoming underscores and things just get totally corrupted after a few times back and forth. The format is absurd as it is, since what Kohana gives me is an array with two entries, the first that at least STARTED normal, while the second was the modified version. The crazy thing there is that the text string that is the JSON I need starts out as being just the key, not the value for the array element. As it gets longer, it will some times be split across the key and the value. For clarity, here's the dump of the array for the first call where I just pass the item id.
array(2) {
["{"item_id":4872}"]=>
string(0) ""
["_item_id_:4872_"]=>
string(0) ""
}
At any rate, if anyone has a good idea on how to deal with this in G3, I'd love to hear it. I've pretty heavily researched online and looked for equivalent examples in G3 itself without much success.
Thanks,
Beo
Reply
Delete
· i_am_lord_beowulf
Nov 1, 2018
View Source
Ok, finally figured it out. Had to manually add a variable name in front of the JSON string. It now looks like:
$.getJSON(<?= html::js_string(url::site("module/function")) ?>, "parms=" + JSON.stringify(parms), handler);
Hope that helps if anyone else needs to do this...
Beo
Reply
Delete
· J.R.
Nov 2, 2018
View Source
Beo,
Good to know you figured it out. This is the kind of thing that caused me to
pretty much give up coding.
-- J.R.
i_am_lord_beowulf wrote:
Show message history
Reply
Delete
· i_am_lord_beowulf
Message 4 of 4 , Nov 2, 2018
View Source
Thanks J.R.,
Guess I should have also included the PHP side as that took a while to find the right combination too, although now it looks simple enough! To received the JSON encoded parameter block:
$json_parms = Input::instance()->get("parms");
$parms = json_decode($json_parms, true);
To reply with a JSON encoded parameter block:
json::reply($parms);
Thanks,
Beo