Getting data from a list using rest API.
Here is my code ,
function getItems(url) {
$.ajax({
url: _spPageContextInfo.webAbsoluteUrl + url,
type: "GET",
headers: {
"accept": "application/json;odata=verbose",
},
success: function (data) {
console.log(data.d.results);
return data.d.results;
},
error: function (error) {
alert(JSON.stringify(error));
}
});
}
Here is the function call,
var result = getItems("/_api/Web/Lists/GetByTitle('LISTNAME')/Items?$select=ID,FIELD1,FIELD2,FIELD3");
I am getting the items in console. But when trying to access 'result
' variable it showing undefined. how can I return the result data. can i solve it by callback, promise or any other way...