下面的代碼應該顯示id
從我從服務器獲得的JSON對象。我找不到這個錯誤,有人可以幫我嗎?先謝謝你!JSON數據將不會通過jQuerys顯示getJSON()
時http://localhost:8387/nscalemc/rest/mon/resourcestatus.json
被稱爲這是返回的JSON對象:
{
"groupStatus": [
{
"id": "Application Layer Configuration-ApplicationLayer",
"time": 1332755316976,
"level": 0,
"warningIds": [],
"errorIds": []
},
{
"id": "Application Layer-ApplicationLayer:nscalealinst2",
"time": 1333431531046,
"level": 0,
"warningIds": [],
"errorIds": []
},
{
"id": "Application Layer-ApplicationLayer:nscalealinst1",
"time": 1333431531046,
"level": 1,
"warningIds": [
"documentarea.locked"
],
"errorIds": []
},
{
"id": "Storage Layer-StorageLayerInstance1",
"time": 1331208543687,
"level": 0,
"warningIds": [],
"errorIds": []
}
]
}
我的HTML文件gadget.html
:
<html>
<head>
<title>Monitor</title>
<link href="css/gadget.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="js/jquery-1.7.2.js"></script>
<script type="text/javascript" src="js/gadget.js"></script>
</head>
<body>
<div id="content"></div>
</body>
</html>
我的JavaScript文件 「gadget.js」:
fetch_JSON();
function fetch_JSON() {
var url = "http://localhost:8387/nscalemc/rest/mon/resourcestatus.json";
$.getJSON(url+'?callback=?', function(data) {
$(data.groupStatus).each(function() {
$('#content').append('<p>ID: ' + $(this).id+ '</p>');
});
});
}
編輯: 謝謝你的解決方案!我通過Firebug的調試,並發現,該的getJSON呼叫狀態爲「401未授權」結束..
btw:是'?callback =?'在getJSON方法中需要? – P4tR 2012-04-03 12:24:47
你確定你的函數正在執行嗎?也許你應該改變你的功能fetch_JSON(){alert('here'); }只是爲了確保 – Churk 2012-04-03 12:26:36
否 - 僅適用於JSONP請求。你可以刪除它。 – 2012-04-03 12:26:37