数据是自己写的db.json然后用json-server运行的,ajax可以打印出来,渲染不上去$(function(){$.ajax({ url:"http://localhost:3000/users", type:"get", data:{}, dataType:"json", success: function(data){ let str = ""; for (var i = 0; i < data.length; i++) { console.log(data[0].name)
str+="<tr>"
+"<td>data[i].name</td>"
+"<td>'+data[i].age+'</td>"
+"<td>'+data[i].phone+'</td>"
+"<td>'+data[i].email+'</td>"
+"<td>'+data[i].education+'</td>"
+"<td>'+data[i].profession+'</td>"
+"</tr>"
};
$('tbody').append(str)
}, error:function(data){
alert('error')
}
})})
2 回答
阿晨1998
TA贡献2037条经验 获得超6个赞
应该是字符串连接问题
str+="<tr>"+ "<td>" + data[i].name + "</td>" + "<td>" + data[i].age + "</td>" + "<td>" + data[i].phone + "</td>" + "<td>" + data[i].email + "</td>" + "<td>" + data[i].education + "</td>" + "<td>" + data[i].profession + "</td>" + "</tr>"
FFIVE
TA贡献1797条经验 获得超6个赞
'<tr>\ <td>'+data[i].name+'</td>\ <td>'+data[i].age+'</td>\ <td>'+data[i].phone+'</td>\ <td>'+data[i].email+'</td>\ <td>'+data[i].education+'</td>\ <td>'+data[i].profession+'</td>\ </tr>'
- 2 回答
- 0 关注
- 509 浏览
添加回答
举报
0/150
提交
取消