json_encode on GoDaddy

json_encode on GoDaddy

jcg31jcg31 Posts: 8Questions: 4Answers: 0

I just moved a project that relies on DataTables to GoDaddy. All is fine until I try to pass the data from PHP to DataTables using json_encode. Bunches of comments how that creates issues on GoDaddy, but no solutions that I have found. Is there a way to pass an array from PHP to DataTables without json_encode?

Answers

  • rf1234rf1234 Posts: 2,997Questions: 87Answers: 421
  • jcg31jcg31 Posts: 8Questions: 4Answers: 0

    Thanks for the quick response.
    I did see that but that doesn't seem to address my issue. I can print_r ($output) and it comes through in response just fine, but not acceptable to DataTables. but when I echo json_encode($output) , nothing is received in response.

  • kthorngrenkthorngren Posts: 21,342Questions: 26Answers: 4,954

    Use the browser's network inspector to see what is in the XHR response. If you see escaped quotes, for example \", in the JSON data then the data is being encapsulated into a JSON string more than once. In this case either change the server script to remove the extra JSON encapsulation or use ajax.dataSrc to convert the JSON string to a Javascript object using .JSON.parse().

    Basically you need to debug the data encapsulations to make sure it happens only once. If you still need help the please post a link to your page or a test case replicating the issue so we can help debug.
    https://datatables.net/manual/tech-notes/10#How-to-provide-a-test-case

    Kevin

  • allanallan Posts: 63,523Questions: 1Answers: 10,473 Site admin

    If you can't provide a link to a test case, can you use the debugger to give me a trace please - click the Upload button and then let me know what the debug code is.

    Allan

  • jcg31jcg31 Posts: 8Questions: 4Answers: 0

    Sorry folks, I was away for a couple days. Thank you for your responses.

    Kevin, I should have been more clear in my last comment.

    I am populating an array ($rowz) in PHP with the results of a mysql query.

    After exiting the while loop I am creating the DataTables wrapper with:

    $output ['aaData'] = $rowz;

    Then:

    echo json_encode($output);

    What I tried to convey in my last comment is that when using json_encode (), I do not receive a response (under Network tab id dev tools). But I can see a response in dev tools when I use print_r().

    On two other (non-GoDaddy) servers the same code presents the JSON fine and populates the DataTable as expected.

  • kthorngrenkthorngren Posts: 21,342Questions: 26Answers: 4,954

    If there is nothing in the response then it sounds like a problem specific to using GoDaddy. I'm not familiar with GoDaddy to help. Not sure what support resources are available for GoDaddy questions. Maybe Stack Overflow would be a good place to ask.

    Kevin

  • allanallan Posts: 63,523Questions: 1Answers: 10,473 Site admin

    I'd also suggest that enabling debug with:

    error_reporting(E_ALL);
    ini_set('display_errors', '1');
    

    at the top of your file would be a good move. And check the server's error logs. My guess is that there will be an error about UTF-8 formatting. You might need to do something like SET NAMES 'utf8' on your database connection.

    Allan

  • jcg31jcg31 Posts: 8Questions: 4Answers: 0

    Thanks Allan,
    No error or warnings in dev tools or the php error log.

    I will give GoDaddy a call. And post the resolution if they come up with one.

  • allanallan Posts: 63,523Questions: 1Answers: 10,473 Site admin

    Sounds good - thanks.

    Allan

Sign In or Register to comment.