Question

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.

Was it helpful?

Solution 2

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

OTHER TIPS

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
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top