I am trying to create an input with id and value attributes set from JSON. I have an ajax call that receives JSON and the data returned is just fine, and for each object from JSON I want to create a button with an identifier and value from JSON.
Ajax call:
$.ajax({
type: "GET",
url: '@Url.Action("GetSubjects", "CommAPI")',
dataType: "json",
success: function (data) {
$.each(data, function (index, element) {
$('#subjects').append('<input type ="button" id=" ' + element.Id + ' " value=' + element.Title + ' class=k-button />');
});
},
});
Objects from JSON, however, have 5 additional properties in them, and not just Id and Title. When placing the debugger in a line with the creation of the input, the identifier and header are undefined.
How can I create these inputs from this JSON?
The returned JSON is copied from the console:
14:41:57.928 {"Data":[{"Id":1,"IdCSite":1,"IdDEvent":1,"Title":"Test","CaseName":null,"Description":"dsadasdasda","InsertedDate":"/Date(-62135596800000)/","SelectedUsers":null,"ViewSelectedUsers":null,"IsCurrentUserIncluded":false},{"Id":2,"IdCSite":1,"IdDEvent":1,"Title":"Test2","CaseName":null,"Description":"sdadasdas","InsertedDate":"/Date(-62135596800000)/","SelectedUsers":null,"ViewSelectedUsers":null,"IsCurrentUserIncluded":false},{"Id":3,"IdCSite":1,"IdDEvent":1,"Title":"test 3","CaseName":null,"Description":"sdadasdasda","InsertedDate":"/Date(-62135596800000)/","SelectedUsers":null,"ViewSelectedUsers":null,"IsCurrentUserIncluded":false}],"Total":3,"AggregateResults":null,"Errors":null}1 messageboard:128:25