[
{
"remoteHostAddress": "127.0.0.1",
"id": 411,
"protocol": "HTTP/1.1",
"userAgent": "Mozilla/5.0 (Windows NT 10.0; WOW64; rv:47.0) Gecko/20100101 Firefox/47.0",
"sessionId": "4B54E10FB6D7A23B45C1BE58EEEF14AA",
"requestURL": "http://localhost:8080/Log4jDemo/",
"remotePort": 59350,
"method": "GET"
},
...
]
$(document).ready(function() {
$(".hidden").val(i);
var data = "";
$.ajax({
type : "get",
url : "http://localhost:8080/Log4jDemo/logs/log",
async : true,
data : data,
dataType : "json",
success : function(data) {
//data此处为json
//alert(data[0].userAgent + data[0].sessionId);
for (var i = 0; i < data.length; i++) {
$("#log").append(
"<div>日志id:" + data[i].id + "</div>"
+ "<div>远程主机iP:"
+ data[i].remoteHostAddress
+ "</div>" + "<div>请求地址:"
+ data[i].requestURL
+ "</div><br/>" + "<div>会话id:"
+ data[i].sessionId + "</div>"
+ "<div>用户代理:" + data[i].userAgent
+ "</div><hr/>");
}
}
});
});
通过Jquery的Ajax方法很容易的得到了json文档,并对其通过append方法循环添加到目标位置