数据在 Ajax Json 上显示为未定义
Data displayed as undefined on Ajax Json
我一直无法将 json 数据解析为 html,但得到了未定义的值。
$.ajax({
type: "GET",
url: "http://localhost/rest/api/kkb/detail/?key=39E62227E3294114BE8EADF3B6D2F06E&id=4",
dataType: 'jsonp',
crossDomain: true,
success: function(data) {
for(var i = 0; i < data.length; i++) {
console.log(data[i].start);
}
success: function (response) {
var trHTML = '';
$.each(response, function (i, item) {
trHTML += '<tr><td>' + item.name + '</td><td>' + item.year + '</td><td>' + item.period + '</td></tr>';
});
$('#records_table').append(trHTML);
},
error: function(e) {
console.log(e);
}
});
};
getUserData();
API url 的结果是:
{"status":true,
"message":"Detail Kkb",
"data": { "kkb": { "id":"4",
"year":"2014",
"periode":"S-I",
"name":"TWA Joe Som"
}
}
}
和 html 代码:<table id="records_table"></table>
但是没有用,它说未定义。当我检查 firebug 中的日志数据时,数据已加载。非常感谢您的帮助
var response= [{"status":true,"message":"Detail Kkb","data":{"kkb":{"id":"4","year":"2014","periode":"S-I","name":"TWA Joe Som"}}}];
var trHTML = '';
$.each(response, function (i, item) {
trHTML += '<tr><td>' + item.data.kkb.name + '</td><td>' + item.data.kkb.year + '</td><td>' + item.data.kkb.period + '</td></tr>';
});
console.log(trHTML);
$('#records_table').append(trHTML);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<table>
<tr id="records_table"></tr>
</table>
我一直无法将 json 数据解析为 html,但得到了未定义的值。
$.ajax({
type: "GET",
url: "http://localhost/rest/api/kkb/detail/?key=39E62227E3294114BE8EADF3B6D2F06E&id=4",
dataType: 'jsonp',
crossDomain: true,
success: function(data) {
for(var i = 0; i < data.length; i++) {
console.log(data[i].start);
}
success: function (response) {
var trHTML = '';
$.each(response, function (i, item) {
trHTML += '<tr><td>' + item.name + '</td><td>' + item.year + '</td><td>' + item.period + '</td></tr>';
});
$('#records_table').append(trHTML);
},
error: function(e) {
console.log(e);
}
});
};
getUserData();
API url 的结果是:
{"status":true,
"message":"Detail Kkb",
"data": { "kkb": { "id":"4",
"year":"2014",
"periode":"S-I",
"name":"TWA Joe Som"
}
}
}
和 html 代码:<table id="records_table"></table>
但是没有用,它说未定义。当我检查 firebug 中的日志数据时,数据已加载。非常感谢您的帮助
var response= [{"status":true,"message":"Detail Kkb","data":{"kkb":{"id":"4","year":"2014","periode":"S-I","name":"TWA Joe Som"}}}];
var trHTML = '';
$.each(response, function (i, item) {
trHTML += '<tr><td>' + item.data.kkb.name + '</td><td>' + item.data.kkb.year + '</td><td>' + item.data.kkb.period + '</td></tr>';
});
console.log(trHTML);
$('#records_table').append(trHTML);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<table>
<tr id="records_table"></tr>
</table>