开发者

Problems with $.getJSON in certain browsers

开发者 https://www.devze.com 2022-12-14 22:14 出处:网络
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

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 cal开发者_运维知识库l to array_merge is the culprit.


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


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

0

精彩评论

暂无评论...
验证码 换一张
取 消