【发布时间】:2018-05-23 00:07:27
【问题描述】:
这是我的问题:我想将通过 Ajax 调用捕获的 JSON 数据放入 HTML div 中。
function showEspece(espece, categorie, object) {
$.ajax({
type: 'POST',
url: 'getespece.php',
data: {
espece: espece,
categorie: categorie
},
dataType: 'json',
success: function(data) {
console.log(data);
$('#output').html(data); //what i try to do but don't work
},
error: function(xhr, status, error) {
console.log(error);
}
});
}
<div id="output"></div>
以下是变量数据包含的内容:
如何在 HTML div 中显示变量的内容 - 特别是在表格中?
【问题讨论】:
-
使用 JSON.stringify 函数
-
您可能需要先对数据进行字符串化。
$('#outpu't).html(JSON.stringify(data)). -
字符串化看起来像这样:{"NOMA":["Chachi","Rafiki","Chakra"],"SEXE":["F","M","F" ],"DATENAISSANCE":["05-MAY-15","07-JAN-15","17-SEP-17"]} 并不是每个人都能真正阅读
-
是的,但它是您可以拥有 JSON 的最易读的形式。
-
使用 JSON.stringify(data,null,4) 以 4 个空格缩进漂亮地打印输出。
标签: javascript jquery html json ajax