I am trying to use REST to get data from inside a SharePoint list. The HTML/ASPX page that makes the request resides in the site assets library. It returns nothing. Any idea why? Please see below:
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
<button onclick="GetListItems();" type="button">Get All List Items</button>
<script>
function GetListItems()
{
var url = _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/getByTitle('Request')/items";
$.ajax({
url: url,
type: "GET",
headers:
{
"accept":"application/json; odata=verbose"
},
success: onSuccess,error: onError
});
}
function onSuccess(data) {
var items = data.d.results;
var allItems='';
for (var i = 0; i < items.length; i++) {
allItems+="Item ID- "+ items[i].Id+ " : Title- " + items[i].Title + '\r\n';
}
alert(allItems);
}
function onError(error) {alert(JSON.stringify(error));
}
</script>
<title>Resttest</title>
</head>
<body>
</body>
</html>