Monday, 22 October 2018

Get the list item using Rest API

Get the list item using Rest API


function GetListItem() {
    var siteUrl = window.location.protocol + '//' + window.location.host + _spPageContextInfo.siteServerRelativeUrl;

    $.ajax({

        url: siteUrl + "/_api/lists/getbytitle('Your List Name')/Items",
        type: "GET",
        headers: {
            "accept": "application/json;odata=verbose",
            "content-type": "application/json;odata=verbose",
            "X-RequestDigest": $("#__REQUESTDIGEST").val()
        },
        success: function(data) {

            var results = data.d.results;

            for (var i = 0; i < results.length; i++) {

                alert(results[i]["Field name"]);


            }

        },
        error: function() {
            console.log('Failed.');
        }
    });
}

No comments:

Post a Comment