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

Clear DataTable on button click

Populate dropdown using jquery ajax in SharePoint

3D Charts in SharePoint