Save Data to SharePoint list using REST Api

How to Save Data to SharePoint list using REST Api

You can use the below code to save data to SharePoint list using REST Api

JS Code:-

$(document).ready(function() {
 $("#btn").click(function(){
    CreateListItem();
 });
});

function CreateListItem()
   { 
    $.ajax
        ({
        url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/GetByTitle('TestRestList')/items",
        type: "POST",
        data: JSON.stringify
        ({
            __metadata:
            {
                type: "SP.Data.TestRestListListItem"
            },
            "Title": "Title"         
        }),
        headers:
        {
            "Accept": "application/json;odata=verbose",
            "Content-Type": "application/json;odata=verbose",
            "X-RequestDigest": $("#__REQUESTDIGEST").val(),
            "X-HTTP-Method": "POST"
        },
        success: function(data)
        {
            alert("Added Successfully");
        },
        error: function(data)
        {
            alert("Error Occured");
        }
    });

}

Comments

Popular posts from this blog

Customizing SharePoint list and implementing Quick search using jQuery

Enable and Disable Client side People Picker using jQuery

How to generate PDF using jsPDF and html2canvas library