I have a PHP script that parses an array using the json_encode() method but returns blank
The PHP Code is as follows
$companies = $db->getCustomerNames();
print_r($companies)
if (!empty($companies)){
$jsonstring = json_encode($companies);
echo $jsonstring ;
}
else{
echo 'false';
}
- $companies is populated and i can print it out yet
I also have a javascript that looks like this
jQuery.ajax({
type: "GET",
url: "http://localhost/myscript.php"
success: function(msg) {
companies = jQuery.parseJSON(msg);
//DO OTHER STUFF WITH companies
}
});
- The PHP script connects to a DB and echo the JSON encoded array
- The Javascript gets the array using AJAX so i can use it’s content
- When I hit http://localhost/myscript.php i get a blank page
- Works fine on my local server
- The page is hosted on Yahoo (not sure if it makes a difference)
Try to use function_exist because on some servers json* functions could be disabled or php is configured to not use it