Javascript 如何使用REST for Sharepoint 2013删除项目
我正在创建一个Sharepoint应用程序,我仅限于使用Javascript(包括jQuery)和REST端点。我想使用web应用从主机上删除一个项目,但我收到一个错误(Javascript 如何使用REST for Sharepoint 2013删除项目,javascript,sharepoint,rest,sharepoint-2013,Javascript,Sharepoint,Rest,Sharepoint 2013,我正在创建一个Sharepoint应用程序,我仅限于使用Javascript(包括jQuery)和REST端点。我想使用web应用从主机上删除一个项目,但我收到一个错误(403:禁止)。这是我目前掌握的代码: executor = new SP.RequestExecutor(appweburl); executor.executeAsync({ url: appweburl + "/_api/SP.AppContextSite(@target)/web/lists/getbytitle
403:禁止
)。这是我目前掌握的代码:
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:probled
消息
有人知道如何使用REST从列表中删除列表项吗(我不能使用/编辑javascript之外的任何代码!)
欢迎提供任何帮助,如果您需要任何信息,请随时询问。该代码不适用于SharePoint 2010,因为api是SP 2013的新代码 [更新]您的意思可能是您的代码在SP 2013预览版中运行?在SP2013 RTM中,您需要使用:
"Accept": "application/json; odata=verbose"
你从哪里得到这个片段的?我正在尝试理解SP.AppContextSite(@target)部分。这是我从一个教程中得到的东西,并且在过去工作过,这不是问题。嗯,实际上解决了问题。。。谢谢嗨,伙计们,我尝试了确切的方法,但是我仍然从获取
X-RequestDigest
部分中获得了403:probled
消息。请问我该怎么办?请告诉我你是如何解决这个问题的。多谢!“X-RequestDigest”:$(“#uu-RequestDigest”).val()-使用sharepoint默认母版页