這裏我返回了數據集作爲Json結果。當我使用'$ .each'函數時,我沒有得到值。如何從Json結果中獲取數據集值
這是我的javascript:
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js">
</script>
<script>
// TODO: Replace with the URL of your WebService app
$(window).load(function() {
var tableName="customtable.Testing";
alert("Script Running");
$.ajax({
type: "POST",
url: "/CMSPages/TestingService.asmx/GetAllCustomTableData",
data: "{ 'customTableName': '" + tableName + "' }",
dataType: "json",
contentType: "application/json; charset=utf-8",
success: function(data) {
var results = data.d;
$.each(results, function(i, result) {
alert(result.ItemID);
});
},
error: function (jqXHR, textStatus, errorThrown) {
alert(jqXHR.responseText);
}
});
});
</script>
這是我的JSON響應:
{"d":"{\"NewDataSet\": \r\n[\r\n{\"Table\": \r\n[\r\n{\"ItemID\":8,\"ItemGUID\":\"5ef65845-1910-4f71-be3e-c2c0a1e47105
\",\"ItemModifiedWhen\":\"\\/Date(1471582785000)\\/\",\"ItemOrder\":null,\"Email\":\"[email protected]
.edu\",\"ItemCreatedWhen\":\"\\/Date(1471582785000)\\/\",\"ItemCreatedBy\":53,\"ItemModifiedBy\":53,
\"FirstName\":\"Kewchang\",\"LastName\":\"Lee\"}\r\n]\r\n}\r\n]\r\n}\r\n"}
雖然這不是有效的JSON。您的測試服務需要輸出適當的JSON。 –
你有沒有試過在data.d上調用Json.parse?所以你會得到'var results = Json.parse(data.d)'? –