I used the below code to get list items but it is going to error function and showing error in alert.
<html lang="en-US">
<head>
<meta charset="UTF-8">
</head>
<script src="http://ajax.aspnetcdn.com/ajax/knockout/knockout-2.2.1.js" type="text/javascript"></script>
<script src="http://code.jquery.com/jquery-1.7.1.js"></script>
<script type="text/javascript">
function insightViewModel() {
var self = this;
self.insights = ko.observableArray([]);
self.GetInsights = function () {
$.ajax({
url: "http://demo/sites/Dev/_api/lists/getbytitle('CountryNames')/items",
type: "GET",
headers: {
"accept": "application/json;odata=verbose",
},
success: function (data) {
debugger;
alert("Get data-"+data.d.results);
self.insights.push(data.d.results);
},
error: function (error) {
alert(JSON.stringify(error));
}
});
}
self. GetInsights();
}
$(document).ready(function () {
insightModel = new insightViewModel();
var insightDiv = document.getElementById("divDatabinding");
insightViewModel();
});
//
</script>
<body>
<div id="divDatabinding">
<table >
<thead>
<tr>
<th>Name</th>
</tr>
</thead>
<tbody data-bind="foreach:insights">
<tr>
<td style="white-space: nowrap">
<span class="spanlink" data-bind="click: function () { $root.RulesopenEditPanel($data) }">
<i class="fa fa-chevron-circle-up"></i>
</span>
</td>
<td style="white-space: pre-wrap" data-bind="text: Title"></td>
<span class="spanlink" data-bind="click: function () { $root.RulesdeleteRecord($data) }">
<i class="fa fa-times"></i>
</span>
</td>
</tr>
</tbody>
</table>
</div>
</body>
</html>
I am getting this error...