Created
March 22, 2014 10:28
-
-
Save vgrem/9704591 to your computer and use it in GitHub Desktop.
Delete operation in SharePoint 2010 REST
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function deleteListItem(webUrl, listName, itemId, success, failure) { | |
getListItemById(webUrl,listName,itemId,function(item){ | |
$.ajax({ | |
url: item.__metadata.uri, | |
type: "POST", | |
headers: { | |
"Accept": "application/json;odata=verbose", | |
"X-Http-Method": "DELETE", | |
"If-Match": item.__metadata.etag | |
}, | |
success: function (data) { | |
success(); | |
}, | |
error: function (data) { | |
failure(data.responseJSON.error); | |
} | |
}); | |
}, | |
function (error) { | |
failure(error); | |
}); | |
} | |
//Usage: delete Task with Id=3 | |
deleteListItem('https://contoso.sharepoint.com/project/','Tasks',3,function(){ | |
console.log('Task has been deleted'); | |
}, | |
function(error){ | |
console.log(JSON.stringify(error)); | |
} | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment