我有一個URL「http://localhost:8888/api/rest/abc
」,它將提供以下json數據。我想使用Jquery或java腳本在我的UI中獲取這些數據。我從幾個小時嘗試這個,但我無法解決它。請建議我幾個解決方案,這將幫助我解決這個問題。如何使用jQuery或Java腳本從URL(Rest API)到UI獲取JSON數據
{
"My-user": [
{
"link": [
{
"href": "http://localhost:8888/api/rest/abc/MI/CH",
"rel": "self",
"type": "application/my.My.My-user+xml",
"title": "rln"
},
{
"href": "http://localhost:8888/api/rest/cabin?MI=mi&CH=ch",
"rel": "some relation",
"type": "application/my.My.My-cabin+xml",
"title": "rln1"
}
],
"My-user-list": [
{
"name": "cuba",
"Explanation": "bark"
}
],
"CH": "ch",
"MI": "mi",
"password": "xyz",
},
{
"link": [
{
"href": "http://localhost:8888/api/rest/abc/DD/KN",
"rel": "self",
"type": "application/my.My.My-user+xml",
"title": "rln"
},
{
"href": "http://localhost:8888/api/rest/cabin?DD=dd&KN=kn",
"rel": "some relation",
"type": "application/my.My.My-cabin+xml",
"title": "rln1"
}
],
"My-user-list": [
{
"name": "Cuba1",
"Explanation": "bark1"
}
],
"KN": "kn",
"DD": "dd",
"password": "xyz1",
}
]
}
我已經試過的getJSON它不工作對我來說這是我的代碼下面請糾正我,如果代碼是錯誤的。
<html>
<head>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.7.2.min.js"></script>
<script>
$.getJSON('/api/rest/abc', function(data) {
console.log(data);
});
</script>
</head>
<body>
</body>
</html>
這是預期的輸出,顯示我們的代碼。你試過什麼了? – 2013-04-11 09:35:51
您好無此URL是通過Node.js生成並啓動服務器後如果我運行服務器localhost:8888/api/rest/abc後打開URL,那麼它將提供以下json,但我希望該json在用戶界面 – Sau 2013-04-11 09:58:34