Reputation: 30170
I have a php file that outputs json encoded text via
echo '(' . json_encode( $final ) . ')';
And i have a javascript file that fetches that page
$.getJSON(file, function(data){
var object = eval(data);
alert(object); //for testing
...
When any browser other than firefox 3.5 visits the page that calls .getJSON it alerts null
BUT!!! If i take the text that is output by the php file paste it into a new file and load that via .getJSON it works fine. It's only when its output by php that it doesn't work.
The only difference i can see is that the PHP file's content length is 2 more than the other, i can't figure out why.
Thanks
a call to array_merge is the culprit.
Upvotes: 0
Views: 313
Reputation: 30170
I've narrowed it down to a call to array_merge
that is corrupting the data somehow.
Upvotes: 0
Reputation: 58979
data
is not a string, it is a JSON object. Therefore eval will not work on it. Try the following instead:
$.getJSON(file, function(data){
alert(data); //for testing
Upvotes: 2