0

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

enter image description here

How do I gain access to the data?

enter image description here

Here's the error I get: enter image description here

  • Is there any updates ? – Jerry_MSFT Nov 12 '19 at 5:38
0

In 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>
0

SharePoint REST update does not return the updated item. You will need to make a second request to get the updated item.

  • How come I see data that is in the success handler? – OLA Nov 11 '19 at 2:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.