0

我在修复此错误时遇到问题。可能有人可以解释这里发生了什么:我正在从服务器返回 JSON:

 d3.json(fullpath, function (json)
        {
            graphData = json;
            if (graphData.nodes.length == 0)
            {
                $.jnotify("Sorry there is no data for graph. Please include social media type in search.");
            }
            drawGraph();
        });

这是json的一部分:

"nodes": [{
        "id": 1,
        "userID": 1,
        "profile_image_url": "images/twitterimage_1.jpg",
        "description": "user1 desc",
        "name": "user 1",
        "location": "Berlin",
        "statuses_count": 5,
        "followers_count": 1
    }
    ,
    {
        "id": 2,
        "userID": 2,
        "profile_image_url": "images/twitterimage_2.png",
        "description": "user2343434 desc",
        "name": "user 2",
        "location": "Berlin",
        "statuses_count": 6,
        "followers_count": 2        
    }

然后在这一行:'if(graphData.nodes.length == 0)'我确实有这个错误:'错误:无法获取属性'nodes'的值:对象为空或未定义'

这仅在 IE 中,在 Chrome 或 Firefox 中不是问题。

请帮忙!

谢谢!

4

1 回答 1

0

好的。问题出在这一行: d3.json(fullpath, function (json)

你知道IE异步json是默认的吗?和 Chrome/Firefox 是否同步调用?

因此,解决方法是从 jquery 库切换到 .ajax 调用:

$.ajax({ url: dataPath, dataType: 'json', async: false, data: null, success: function (response) { }

谢谢!

于 2013-01-23T22:46:22.953 回答