Just developed the administration and of course using some JSON objects was crucial. To make it happen I there are some simple steps;
1- Do we have JSON support on the server?
Simply put
"<?php echo phpinfo();?>" in a php file and check if you have JSON enabled.
2- Encode the variable(s) you want to return.
With JSON enabled server, you get to use function
"json_encode($variable)". Create your mixed variable and return the result.
Warning: Do NOT forget to set headers.
header('Cache-Control: no-cache, must-revalidate');
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
header('Content-type: application/json');
3- Don't try to discover America twice.
Getting JSON item with an AJAX query and trying to parse it is of course discovered and coded many times. Use any javascript framework you like to have some easy coding. I used on my page
PrototypeJS. Quite stable and perfectly helpful script. Here goes an example from my site to get an idea how to use.
new Ajax.Request('json.php', {
method:'get',
parameters: {blogId: val},
requestHeaders: {Accept: 'application/json'},
onSuccess: function
..