views:

85

answers:

2

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


UPDATE
I created a small array to test it with other data and it's working. There's something in my data that's causing the issue. Looking now...

a call to array_merge is the culprit.

+2  A: 

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
Marius
still returning null in all browsers except firefox 3.5
Galen
Try removing the brackets from php. There isn't really any point in having them there.
Marius
A: 

I've narrowed it down to a call to array_merge that is corrupting the data somehow. Thanks

Galen