I used REST API to update list items but I am unable to access the results that is passed to the success handler. See image below
How do I gain access to the data?
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It only takes a minute to sign up.
Sign up to join this communityIn the Update Success handler, do another Request to get the item which is updated like this:
<script type="text/javascript">
$(function(){
UpdateListItem(6);
});
function UpdateListItem(id) {
var title = $("#Title").val();
$.ajax
({
url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/GetByTitle('MyList')/items('"+id+"')",
type: "POST",
data: JSON.stringify
({
__metadata:
{
type: "SP.Data.MyListListItem"
},
Title: title
}),
headers:
{
"Accept": "application/json;odata=verbose",
"Content-Type": "application/json;odata=verbose",
"X-RequestDigest": $("#__REQUESTDIGEST").val(),
"IF-MATCH": "*",
"X-HTTP-Method": "MERGE"
},
success: function (data, status, xhr) {
ReadListItem(id);
},
error: function (xhr, status, error) {
console.log(data.responseJSON.error);
}
});
}
function ReadListItem(id)
{
$.ajax({
url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/GetByTitle('MyList')/items('"+id+"')",
type: "GET",
headers: {
"accept": "application/json;odata=verbose",
"content-Type": "application/json;odata=verbose"
},
success: function (data) {
console.log(data.d);
console.log(data.d.Title);
},
error: function (error) {
alert(JSON.stringify(error));
}
});
}
</script>
SharePoint REST update does not return the updated item. You will need to make a second request to get the updated item.