最近,須要在SharePoint上傳文件到文檔庫,可是,上傳的過程報錯了。html
錯誤代碼git
{ "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." } } }
操做就是調用SharePoint Plus 添加文檔github
https://aymkdn.github.io/SharepointPlus/files.html#createFileweb
有興趣的能夠看一下這個插件,原本覺得是插件的問題,後來發現並非。ajax
發現插件在執行這個方法的時候,實際上是Call REST Service。json
而後,調用了REST API上傳,也是報同樣的錯誤。api
後來發現,是Request Digest token須要刷新一下:app
$.ajax({ url: _spPageContextInfo.webAbsoluteUrl + "/_api/contextinfo", method: "POST", headers: { "Accept": "application/json; odata=verbose"}, success: function (data) { $('#__REQUESTDIGEST').val(data.d.GetContextWebInformation.FormDigestValue) }, error: function (data, errorCode, errorMessage) { alert(errorMessage) } });
執行完上面的代碼之後,就能夠正常上傳文件了。完事兒之後,有想了想爲何,多是由於根網站集調用同web application下其餘網站集吧。網站