CustomCodes‎ > ‎

Getting sharepoint list data using REST

$(document).ready(function () {
 
    try {
        getData('MY_LIST_NAME');
    }
    catch (error) {
        console.log('Error in docReady: ' + error.message);
    }
});
 
function getData(strListTitle) {
    var currentSite = _spPageContextInfo.webAbsoluteUrl;
    var ListItemURL = currentSite + "/_api/Web/Lists/GetByTitle('" + strListTitle + "')/items";
    $.ajax({
        url: ListItemURL,
        async: false,
        type: "GET",
        headers: { "accept": "application/json;odata=verbose" },
        success: function (data) {
            $.each(data.d.results, function (index, item) {
                alert(item.CountryShortTitle + " # " + item.Title);
            });
        },
        error: function (error) {
            console.log('Error in getData: ' + error.message);
        }
    });
}