Cheers all!
I searched on this subject to no avail.
I'm playing with json on my website. I'm using a hosting account and am on a server that has php 5.2.3.
I can't seem to get json to work. my first page calls a second page and I can't tell if the problem is in the first or second page, or both. I've basically copy-pasted from code I know works, but it won't work on my site.
Calling page code: (in part)
I have a select box with customer names and id="cust_id".
I have a div with id="filter-results".
<script type="text/javascript">
$(document).ready(function(){
// Your code here
$("#filter-results").html("Search Results will appear here!.");
$("#cust_id").bind("change",function(e){
$.getJSON("jquery-get-customer.php", { cust_id: $("#cust_id").val() }, function(data) {
alert("we are here");
$("#filter-results").empty();
});
});
});
</script>
jquery-get-customer.php code:
<?php
require_once('includes/myUtils.php');
if( $cust_id ){
$sql = "select *
from customers
where cust_id = ?";
$results = $globalMySqlConnect->query($sql, array($cust_id));
if(DB::isError($results)){
die("Error: select from customers failed. ".$results->toString());
}
if($data=$results->fetchRow(DB_FETCHMODE_ASSOC)){
print json_encode($data);
}
}
?>
Testing:
page1: I can print alert() statements up to the .getJSON line, not after it, though. The line: alert("we are here"); does not run.
I can run the code on jquery-get-customer.php by typing in the url and passing in a value that way. When I do this, I get the json_encode() error of:
Fatal error: Call to undefined function: json_encode()
Is there anything I can do to get this working? Do I need to ask my hosting company to enable json or something?
Thanks for any tips.
JC