Your json.js file is not valid JSON. It is executable JavaScript code, but any actual JSON parser will reject it.
JSON is a limited subset of JavaScript and cannot contain function definitions: http://json.org/ -Mike > From: [EMAIL PROTECTED] > > Has nothing to do with jQuery directly, but there's alot of > really great developers here, so maybe I'm missing something > that someone else will catch... > > -------------------------------------------------------------- > ------------------------ > [json.js] > { > "itemtitle1": function(){ > alert("this is item title 1's callback"); > }, > "itemtitle2": function(){ > alert("this is item title 2"); > } > } > -------------------------------------------------------------- > ------------------------ > > This works great in Javascript- exactly how I want it > -------------------------------------------------------------- > ------------------------ > mainscript.js > $.getJSON("json.js",{}, > function(json) { > json.itemtitle1(); // fires the alert for itemtitle1 > } > ); > -------------------------------------------------------------- > ------------------------ > > The problem arises when I use the same json.js in my PHP script > -------------------------------------------------------------- > ------------------------ > mainpage.php > $json=json_decode(file_get_contents('json.js'),1); > -------------------------------------------------------------- > ------------------------ > > > Note that if I change the function in json.js to a string of > text or a boolean etc., then the php file works fine- for > some reason it's not parsing my javascript function, even > though that works [because JSON is an object, my json.js has > a function named itemtitle1. I don't expect PHP to run or > convert my function, but I need to be able to use json.js in > my php script. > > Any ideas? Is this invalid JSON, even though it's valid > javascript, or is it json_encode()'s fault?