Home
> SharePoint 2013 > SharePoint 2013 – Read List Items using REST API
SharePoint 2013 – Read List Items using REST API
SharePoint 2013 introduced Rich REST endpoints, we can use this to query data asynchronously using jQuery/JavaScript.
Here is a sample code which can be used to read items from a SharePoint list
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(i = 0; i < results.length;i++) { console.log(results[i]["Title"]) } }, error: function() { console.log('fail'); } });
We are dynamically forming the site url using various tokens.
First we need to get the SharePoint list, for that we use REST method GetByTitle
and pass the list title. Then we are selecting the item Title
. You can add more fields by separating with comma.
The result is then converted to JSON object using JSON.Parse
method.
Finally a loop is used to iterate through the items.
Categories: SharePoint 2013
ajax, jQuery, REST, SharePoint
Reblogged this on El Blog del Programador and commented:
Aquí tenemos otro interesante artículo sobre cómo utilizar los servicios REST para leer listas de SharePoint. En un post anterior veíamos el acceso a listas de SharePoint 2013 a través de la API de cliente y AngularJS, el ejemplo de hoy utiliza JQuery y las opciones de Ajax de esta librería. Un saludo. Espero ya, poder dedicar algo de tiempo a hacer un ejemplo usando todo esto que vemos aquí.