Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I'm creating an ajax app using jQuery 1.4.2 and I've tried using using get(), post() and the ajax() method itself. My php service returns:

[{"k":"label0","v":0.5},{"k":"label1","v":99.43},{"k":"label2","v":2.46},{"k":"label3","v":46.29},{"status":"OK"}]

in my success callback I have tried accessing as json.status and json[0][0] but it always returns "undefined". what am I doing wrong?

function getSysinfo(source) {
    var json = null;
    $.ajax({
        url: source,
        type: 'POST',
        dataType: 'json',
        success: function (data) {
            json = eval("(" + data + ")");
            $('#data').html(json.status);
            alert(json[0][0]);
            refreshChart(json);
        },
        error: function (request, status, error) {
            alert("REQUEST:" + request + "
STATUS:" + status + 
                  "
ERROR:" + error);
        }
    });
    return json;
}

I've been googling this for days. How the heck do I access the returned data? any help would be appreciated.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
253 views
Welcome To Ask or Share your Answers For Others

1 Answer

To access that status value you would need:

data[4].status

This is because it is an object stored in the the fifth element in an array, with status being a property on the object.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...