Saturday, 12 July 2014

SharePoint REST read list Items

readItem: function (id) {
$.ajax(
{
url: _spPageContextInfo.webServerRelativeUrl +
"/_api/web/lists/getByTitle('Contacts')/getItemByStringId('" +
id + "')/?$select=FirstName,Title,WorkPhone",
type: "GET",
headers: {
"accept": "application/json;odata=verbose",
},
success: function (data) {
REST.FormFiller.fill(data.d.Title, data.d.FirstName, data.d.WorkPhone);
},
error: function (err) {
alert(JSON.stringify(err));
}
}
);
},
readAll: function () {
$.ajax(
{
url: _spPageContextInfo.webServerRelativeUrl +
"/_api/web/lists/getByTitle('Contacts')/items/" +
"?$select=Id,FirstName,Title,WorkPhone" +
"&$orderby=Title,FirstName",
type: "GET",
headers: {
"accept": "application/json;odata=verbose",
},
success: function (data) {
REST.TableRenderer.set_data(data.d.results);
REST.TableRenderer.render();
},
error: function (err) {
alert(JSON.stringify(err));
}
}
);
}