I'm developing a SharePoint App where I need to delete a number of photos that the user will select, so I have a function that I pass an array with the URLs of the photos that will be deleted, but I don't know why it isn't working. This is the function I'm using!
function deleteFiles(arrayURLs) {
var siteUrl = _spPageContextInfo.siteAbsoluteUrl;
var webUrl = _spPageContextInfo.webAbsoluteUrl
var scriptbase = siteUrl + "/_layouts/15/";
$.getScript(scriptbase + "SP.RequestExecutor.js", ejecutarCrossDomain());
function ejecutarCrossDomain() {
var executor = new SP.RequestExecutor(webUrl);
for (var i = 0, len = arrayURLs.length; i < len; i++) {
var urlRest = webUrl + "/_api/sp.appcontextsite(@target)/web/getfilebyserverrelativeurl('" + arrayURLs[i] + "')?@target='" + siteUrl + "'";
console.log(urlRest)
executor.executeAsync({
url: urlRest,
type: "POST",
headers: {
"accept": "application/json;odata=verbose",
"content-type": "application/json;odata=verbose",
"X-RequestDigest": $("#__REQUESTDIGEST").val(),
"X-HTTP-Method": "DELETE",
"IF-MATCH": "*"
},
success: succes,
error: function (error) {
alert(JSON.stringify(error));
loadingOff();
}
});
}
}
function succes() {
console.log('Deleted');
}
}
When I try it, it seems like it work, logging the Deleted in the console too. Thanks to the one that can help me!!