Quantcast
Channel: SharePoint 2013 - Development and Programming forum
Viewing all articles
Browse latest Browse all 7589

REST + jQuery: Can enumerate lists but not get list items

$
0
0

I am attempting to consume data from a SharePoint list in a non-SharePoint application using jQuery.  I have enabled anonymous access on the SharePoint site and have added CORS headers to SharePoint via IIS to facilitate this.  In my JavaScript code, I can do the following:

var siteUrl = 'http://mySharePointSite';
$.ajax({
	url: siteUrl + '/_api/web/lists',
	method: 'GET',
	cache: false,
	headers: { 'Accept': 'application/json; odata=verbose' },
	success: function (data) {
		console.log(data);
	},
	error: function(data, errorCode, msg) {
		console.log('Error: ' + msg);
	}
});

I can also get the properties of a list:

var siteUrl = 'http://mySharePointSite';
$.ajax({
	url: siteUrl + "/_api/web/lists/getByTitle('Headlines')",
	method: 'GET',
	cache: false,
	headers: { 'Accept': 'application/json; odata=verbose' },
	success: function (data) {
		console.log(data);
	},
	error: function(data, errorCode, msg) {
		console.log('Error: ' + msg);
	}
});

However, when I try to get items from the list, I always got 0 results even though there are items in the list:

var siteUrl = 'http://mySharePointSite';
$.ajax({
	url: siteUrl + "/_api/web/lists/getByTitle('Headlines')/Items",
	method: 'GET',
	cache: false,
	headers: { 'Accept': 'application/json; odata=verbose' },
	success: function (data) {
		console.log('Got ' + data.d.results.length + ' results.');
	},
	error: function(data, errorCode, msg) {
		console.log('Error: ' + msg);
	}
});

The list inherits permissions from the parent web, so I don't believe I need to set additional permissions on the list.  How can I query everything about the list except what is in it?

PS: I have also attempted to use the cross domain library with no luck.  Every time I queried SharePoint with the following:

var siteUrl = 'http://mySharePointSite';
var request = new SP.RequestExecutor(siteUrl);
request.executeAsync({
	url: siteUrl + "/_api/web/lists",
	method: 'GET',
	headers: { 'Accept': 'application/json; odata=verbose' },
	success: function(data) {
		console.log(data);
	},
	error: function(data, errorCode, msg) {
		console.log('Error: ' + msg);
	}
});

I always got the following result in the console:

Error: App Web is not deployed for this app's request url http://mySharePointSite.


Viewing all articles
Browse latest Browse all 7589

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>