Monday 8 May 2017

Delete SharePoint list item using REST API

Solution:

Here I create 1 variable as follow:

1)      url : REST API with list name

var url = "/_api/Web/Lists/GetByTitle('CRUDList')/getItemById('1')";


Function:

            function deleteItem(url) {
                $.ajax({
                    url: _spPageContextInfo.webAbsoluteUrl + url,
                    type: "DELETE",
                    headers: {
                        "accept": "application/json;odata=verbose",
                        "X-RequestDigest": $("#__REQUESTDIGEST").val(),
                        "If-Match": "*"
                    },
                    success: function (data) {
                       alert("Record deleted.");
                    },
                    error: function (error) {
                        alert(JSON.stringify(error));
                    }
                });
            }


Function call:

deleteItem(url);


Feel free to revert in-case of any query...


Product Applies To:

·         SharePoint Server 2013

·         SharePoint Foundation 2013

 

No comments:

Post a Comment