Wednesday, December 2, 2020

Display SharePoint list items using rest api

 <div>

<input type="button" id="btnSubmit" value="Get List Details" />

</div>

<div id="divResults"></div>


<script>

$(function () {

$("#btnSubmit").on("click", function () {

getListData();

});

});


function getListData() {

var fullUrl = _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/getByTitle('Projection')/items";

$.ajax({

url: fullUrl,

type: "GET",

headers: {

"accept": "application/json;odata=verbose",

"content-type": "application/json;odata=verbose",

},

success: onQuerySucceeded,

error: onQueryFailed

});

}


function onQuerySucceeded(data) {

var listItemInfo = ";

$.each(data.d.results, function (key, value) {

listItemInfo += '<b>Title:</b> ' + value.Title + ' – <b>Billable hours:</b> ' + value.BillableDays + '<br />';

});

$("#divResults").html(listItemInfo);

}

function onQueryFailed() {

alert('Error!');

}

</script>

No comments:

Post a Comment