我正在创建一个Sharepoint应用程序,受限于使用JavaScript(包括jQuery)和REST端点。我想使用Web应用程序从主机中删除项目,但是我遇到了错误(403:FORBIDDEN
)。到目前为止,这是我的代码:
executor = new SP.RequestExecutor(appweburl);
executor.executeAsync({
url: appweburl + "/_api/SP.AppContextSite(@target)/web/lists/getbytitle('" + currentListTitle + "')/items(" + result.Id + ")/?@target='" + hostweburl + "'",
method: "POST",
headers: {
"accept": "application/json",
"X-RequestDigest": ?????
"IF-MATCH": "*",
"X-HTTP-Method": "DELETE"
},
success: onDeleteItemSuccess,
error: onDeleteItemFail
});
现在我发现X-RequestDigest
是必需的,我发现一些REST调用可以获取它:
$.ajax({
url: appweburl + "/_api/SP.AppContextSite(@target)/contextinfo/?@target='" + hostweburl + "'",
type: "POST",
contentType: "application/x-www-url-encoded",
dataType: "json",
success: function (data) {
if (data.d)
{
digestValue = data.d.GetContextWebInformation.FormDigestValue;
alert(digestValue);
}
},
error: function (xhr) {
alert(xhr.status + ': ' + xhr.statusText);
}
});
但是它根本不起作用(这可能是因为这段代码是为Sharepoint 2010编写的),并且会一直给我一个403:FORBIDDEN
消息。
有人知道如何使用REST从其中一个列表中删除列表项吗(我不能在javascript之外使用/编辑任何代码!)?
任何帮助都将不胜感激,如果您需要任何信息,请不要犹豫询问。