locked
Rest API Update Item not reflect real time changes RRS feed

  • Question

  • Currently, we update list item with Rest API, so far it's working as expected.

    But have one problem, the changes will display until we refresh the list manually, how can we make it automatically.

    Wednesday, November 6, 2019 6:31 AM

Answers

  • Hi zimi,

    You could add the Rest API in the list view page and in Rest Success function, refresh the page using window.location.reload to see the item value changes in list UI:

    $.ajax({  
        url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/GetByTitle('Your List Name')/items(Your record ID)",  
        type: "POST",  
        headers: {  
            "accept": "application/json;odata=verbose",  
            "X-RequestDigest": $("#__REQUESTDIGEST").val(),  
            "content-Type": "application/json;odata=verbose",  
            "IF-MATCH": "*",  
            "X-HTTP-Method": "MERGE"  
        },  
        data: "{__metadata:{'type':'SP.Data.YourlistnameListItem'},Title:"  
        Ur new input "}",  
        /*where Title is column name and add your desired new data*/  
        success: function(data) {  
            console.log(data.d.results);
    	window.location.reload(true);
        },  
        error: function(error) {  
            alert(JSON.stringify(error));  
        }  
    });  

    Thanks

    Best Regards


    Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    SharePoint Server 2019 has been released, you can click here to download it.
    Click here to learn new features. Visit the dedicated forum to share, explore and talk to experts about SharePoint Server 2019.

    Thursday, November 7, 2019 3:03 AM

All replies

  • Hi

    Do you mean it is not reflected on the site UI?


    Justin Liu Office Apps & Services MVP, MCSE
    Senior Software Engineer
    Learn Microsoft 365 from Microsoft DOCs now!
    Please Vote and Mark as Answer if it helps you.

    Wednesday, November 6, 2019 7:52 AM
  • Hi zimi,

    You could add the Rest API in the list view page and in Rest Success function, refresh the page using window.location.reload to see the item value changes in list UI:

    $.ajax({  
        url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/GetByTitle('Your List Name')/items(Your record ID)",  
        type: "POST",  
        headers: {  
            "accept": "application/json;odata=verbose",  
            "X-RequestDigest": $("#__REQUESTDIGEST").val(),  
            "content-Type": "application/json;odata=verbose",  
            "IF-MATCH": "*",  
            "X-HTTP-Method": "MERGE"  
        },  
        data: "{__metadata:{'type':'SP.Data.YourlistnameListItem'},Title:"  
        Ur new input "}",  
        /*where Title is column name and add your desired new data*/  
        success: function(data) {  
            console.log(data.d.results);
    	window.location.reload(true);
        },  
        error: function(error) {  
            alert(JSON.stringify(error));  
        }  
    });  

    Thanks

    Best Regards


    Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    SharePoint Server 2019 has been released, you can click here to download it.
    Click here to learn new features. Visit the dedicated forum to share, explore and talk to experts about SharePoint Server 2019.

    Thursday, November 7, 2019 3:03 AM