admin管理员组文章数量:1410717
I'm creating a Sharepoint App and i am restricted to using Javascript (jQuery included) and REST endpoints. I would like to delete an item from the host using the web app, but i'm getting an error (403: FORBIDDEN
). This is the code i have so far:
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
});
Now I found out this X-RequestDigest
is mandatory and i found some call to get this from 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);
}
});
But it isn't working at all (this might be because this code was for Sharepoint 2010) and it will keep giving me a 403: FORBIDDEN
message.
Does anyone know how to delete a list item from one of the lists using REST (I can't use/edit any code outside of the javascript!)?
Any help is appriciated and if you need any information please don't hesitate to ask.
I'm creating a Sharepoint App and i am restricted to using Javascript (jQuery included) and REST endpoints. I would like to delete an item from the host using the web app, but i'm getting an error (403: FORBIDDEN
). This is the code i have so far:
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
});
Now I found out this X-RequestDigest
is mandatory and i found some call to get this from 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);
}
});
But it isn't working at all (this might be because this code was for Sharepoint 2010) and it will keep giving me a 403: FORBIDDEN
message.
Does anyone know how to delete a list item from one of the lists using REST (I can't use/edit any code outside of the javascript!)?
Any help is appriciated and if you need any information please don't hesitate to ask.
Share Improve this question asked Nov 30, 2012 at 20:23 ManuelManuel 10.3k5 gold badges44 silver badges61 bronze badges 2- 1 Where did you get the snippet from? I am trying to understand the SP.AppContextSite(@target) part. – Christophe Commented Dec 1, 2012 at 1:18
- That is something i got from a tutorial and has worked in the past, that isn't the problem. – Manuel Commented Dec 3, 2012 at 8:25
1 Answer
Reset to default 4The code can't be for SharePoint 2010, as _api is new to SP 2013.
[Update] Maybe you mean that your code was working in SP 2013 preview? In SP2013 RTM you need to use:
"Accept": "application/json; odata=verbose"
本文标签: javascriptHow to delete an item using REST for Sharepoint 2013Stack Overflow
版权声明:本文标题:javascript - How to delete an item using REST for Sharepoint 2013 - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744783167a2624837.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论