SharePoint 2013 - Read List Items using REST API
Read items from a SharePoint 2013 list with the REST API and jQuery, selecting only the fields you need.
SharePoint 2013 introduced rich REST endpoints. You can use them to query list data asynchronously with jQuery or plain JavaScript.
This sample reads items from a list:
js
var siteUrl = window.location.protocol + "//" + window.location.host + _spPageContextInfo.siteServerRelativeUrl;
jQuery.ajax({
url: siteUrl + "/_api/lists/getbytitle('ListTitle')/Items?$select=Title",
type: "GET",
headers: {
"accept": "application/json;odata=verbose",
"content-type": "application/json;odata=verbose",
"X-RequestDigest": jQuery("#__REQUESTDIGEST").val()
},
success: function (d) {
var stringData = JSON.stringify(d);
var jsonObject = JSON.parse(stringData);
var results = jsonObject.d.results;
for (var i = 0; i < results.length; i++) {
console.log(results[i]["Title"]);
}
},
error: function () {
console.log('fail');
}
});
How it works:
- The site URL is built from the current page using
_spPageContextInfo. getbytitlefinds the list by its title.$select=Titlereturns only theTitlefield. Add more fields separated by commas.- The result is converted to a JSON object with
JSON.parse. - A loop goes through the items in
d.results.
Example
With a list called "Tasks", replace ListTitle with Tasks. The console then shows the title of every task, one per line.