jQuery .getJSON()不显示数据

时间:2014-03-17 20:54:39

标签: javascript jquery ajax getjson

我收到了这个输出:

0 [object Object] 
1 [object Object] 
2 [object Object] 
3 [object Object] 

jQuery的:

$.getJSON(url, {
    sessionId: "1"
}).done(function(data) {
    alert("Successfully got the messages! ");

    $target.empty();

    var messages = [];

    $.each(data,function(k,v) {

        console.log(k + " " + v);

    });


    $target.append(data);
}).fail(function() {
    alert("Could not reload messages!");
});

回应:

[
  {
    "date": "2014-02-19",
    "user_viewer": null,
    "message": "Hey mate, can you do 20:00?",
    "user_op": "john",
    "time": "18:21:00"
  },
  {
    "date": "2014-02-20",
    "user_viewer": null,
    "message": "@simon, you can borrow one from the desk, it's 1 pound.",
    "user_op": "roger",
    "time": "00:00:00"
  }
]

1 个答案:

答案 0 :(得分:1)

使用:

$.getJSON(url, {
    sessionId: "1"
}).done(function(data) {
    alert("Successfully got the messages! ");

    $target.empty();

    var messages = [];

    $.each(data,function(k,v) {
        console.log(k + " " + JSON.stringify(v));
    });


    $target.append(data);
}).fail(function() {
    alert("Could not reload messages!");
});