0
我想在HTML5頁面中綁定來自WebAPI調用的json響應。不知道我在哪裏。在返回的WebAPI這JSON:從HTML5調用WebAPI頁面
{
"ID": 1,
"Date": "2015-10-26T00:00:00",
"Status": "Initiated",
"Action": {
"VerificationActionTypeID": 0,
"VerificationActionType": null,
"VerificationActionTakenID": 0,
"VerificationActionTaken": null,
"VerficationActionCreateDate": "0001-01-01T00:00:00",
"EmailAddress": null,
"Notes": null
},
"Actions": [
{
"VerificationActionTypeID": 0,
"VerificationActionType": "Perform Rinse Flowcell",
"VerificationActionTakenID": 0,
"VerificationActionTaken": "Skip",
"VerficationActionCreateDate": "2015-10-26T10:04:05.093",
"EmailAddress": null,
"Notes": null
}
]
}
這是我的jQuery代碼:
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script type="text/javascript">
var uri = 'http://localhost/Custom.WebAPI/api/action?verificationid=1';
var $result = $('#Result');
var msg;
$(document).ready(function() {
$.getJSON(uri)
.done(function (data) {
$.each(data, function (key, item) {
alert("action: " + item);
$('#actions tbody').append('<tr><td>' + item.ID + '</td><td>' + item.Status + '</td></tr>');
});
})
.fail(function (jqXHR, textStatus, err) {
var error = $.parseJSON(jqXHR.responseText);
msg = "Failed to get action data Error message is " + error.message;
alert("Message: " + msg);
});
});
</script>
我的HTML:
<body>
<aside id="data">
<div id="Result"> </div>
<table id="actions">
<thead>
<tr>
<td>ID</td>
<td>Status</td>
</tr>
</thead>
<tbody></tbody>
</table>
</aside>
</body>
這是顯示在HTML頁面上:
注意這條線我在JavaScript:
警報( 「行動:」 +項目);
它顯示警報消息是這樣的:
我只是想顯示在HTML表中的結果。不知道我做錯了什麼。感謝您的任何幫助,您可以提供。