开发者

jQuery JSON Callback says 'Undefined'

开发者 https://www.devze.com 2023-01-12 19:05 出处:网络
I\'m creating this script which loads the data from JSON which is encoded in a PHP file (the JSON is valid).

I'm creating this script which loads the data from JSON which is encoded in a PHP file (the JSON is valid).

When a div is clicked on开发者_C百科, it should show the data from the jQuery, which is done here:

function quickView(pid) {
    $.getJSON('project.php', { id: pid, view: 'true' }, function(data) {
      $('#view-' + pid).html('<p>' + data.name + '</p>'
        + '<p>' + data.deadline + '</p>');
    });
}

The HTML:

<a href="project.php?id=1">
    <div class="row-null">
        <p>An example project</p>
    </div>
</a>
<div class="row-null quick-view" id="view-1" title="Quick View" onclick="quickView(1);">
    <p><img src="img/pixel.png" height="5" width="9" alt="" /></p>
</div>

However when I click on it, it opens and says Undefined...

The JSON when outputted:

[
    {
        "name": "Another example project",
        "description": "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry\\'s standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.",
        "deadline": "Tuesday 24th August 2010"
    }
]

What's the problem?


Your server is returning an array, so you want data[0].name.

0

精彩评论

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

关注公众号