I need to create an app for sharepoint that does the simple task of listing fields from a list on the screen where the App is placed inside Sharepoint.
I have the following error: In 'Access-Control-Allow-Origin' header is present on the requested resource.
This code is within the default.aspx created by Napa:
<div ng-app>
<b>Lista simples AngularJS + Sharepoint!</b>
<div ng-controller="MyController" class="ng-scope">
<div ng-repeat="p in Products">
Product Name: {{p.ProductName}} <br />
Rate: Rs. {{p.ProductRate}} <br />
<hr />
</div>
</div>
</div>
<script>
function MyController($scope) {
$scope.loadREST = function () {
jQuery.ajax({
url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/getbytitle('ProductList')/items?$select=ProductName,ProductRate",
type: "GET",
dataType: "JSONP",
headers: { "Accept": "application/json;odata=verbose" },
success: function (data) {
var newData = [];
jQuery.each(data.d.results, function (index, value) {
newData.push({ ProductName: value.ProductName, ProductRate: value.ProductRate});
});
$scope.$apply(function () {
$scope.Products = newData;
});
},
error: function () {
//alert(_spPageContextInfo.webAbsoluteUrl);
alert("erro de conexão");
}
});
};
$scope.loadREST();
}
</script>