我正在尝试使用Sharepoint 2013上的rest api创建一个简单的列表项。我的代码:
$.ajax({ url: siteUrl + "/_api/web/lists/getByTitle('internal_Listname')/items", type: "POST", contentType: "application/json;odata=verbose", data: JSON.stringify({ '__metadata': { 'type': 'SP.Data.internal_ListnameListItem', }, 'K1F1': k1f1Result, }), headers: { "accept": "application/json;odata=verbose", "X-RequestDigest": $("#__REQUESTDIGEST").val(), }, success: function (data) { console.log("done"); }, error: function (err) { console.log(JSON.stringify(err)); } });
尝试发送数据时,出现403“禁止”错误。
"error":{ "code":"-2130575251, Microsoft.SharePoint.SPException", "message":{ "lang":"en-US", "value":"The security validation for this page is invalid and might be corrupted. Please use your web browser's Back button to try your operation again." } }
几天前找到了解决方案:我忘记将请求摘要表格添加到正文中。它应具有以下结构;
<form runat="server"> <SharePoint:FormDigest ID="FormDigest1" runat="server"></SharePoint:FormDigest> </form>