asked 1 year ago by Aleks G
This code works fine. When executed on my local linux machine or my mac, the passed data is decoded correctly and everything works fine. However when the same code is executed on godaddy shared hosting, the decoding fails with Syntax error. Having spent a lot of time trying to narrow down the problem, I found out that the problem occurs when I have
As you can see, the value of the POST parameter is created using
If the last element in the array (with task Assign Role) is removed, then everything is processed successfully. If I replace
Two questions arise from this:
Anybody can shed some light on this situation?
I'm not sure if this is it or not, but if you're pulling the data from a database then you have to set the utf8 encoding when inserting it into the database in order to prevent json from dropping pieces of it.
Before the insert:
$text = utf8_encode($text);
If that's not exactly what you are doing I'm willing to bet the answer is really close to that.
To enable the JSON extension on your hosting account, you must modify the php5.ini file to include the following code:
For whatever reason, on godaddy hosting only (maybe in some other places too, but not in other places I tested), when I was submitting the form, the server was escaping quotes - and that's what was causing the issue. The solution to the problem was quite simple: instead of doing
$data = json_decode($_POST['logdata'], true);
$data = json_decode(stripslashes($_POST['logdata']), true);
and everything worked perfectly.
Viewed: 208 times
Last updated: Dec 22, 2012