跨域的SharePoint REST API批处理操作 [英] SharePoint REST api batch operations in cross domain
问题描述
我在相同的原则下有2个网站集,称为Site1& Site2.
我需要从Site2中提取信息并显示在Site1上.
还具有多个过滤条件,以从site2获取数据.因此,我打算使用REST API端点来提取信息.
为了避免多次击中服务器,我计划使用REST API批处理请求.
由于它是跨域平台格式,我的Batch请求不起作用,并且我收到403禁止的异常.
请与您分享建议或使用带有批处理请求的客户端脚本从另一个网站集中获取信息的替代方法.
预先感谢.
Sugumaran Srinuvasan
您是否使用"/_ api/contextinfo"获得了X-RequestDigest?先休息api吗?
以下示例有关使用REST API和jQuery Ajax从另一个网站集中获取列表项的示例.
< script type =" text/javascript"src ="//code.jquery.com/jquery-1.12.4.min.js"</script> < script type ="text/javascript">
(function(){ var otherSiteUrl ="http://sitecollection1/"; var listName ="TestList"; //获取其他网站集的表单摘要值
.ajax({ url:otherSiteUrl +"/_ api/contextinfo", 类型:"POST",//尝试获取用户POST的上下文信息时,将其用作类型而不是方法,因为发送请求时正文为空 标头:{ 接受":"application/json; odata = verbose"; }, 成功:function(contextData){ //alert(contextData.d.GetContextWebInformation.FormDigestValue);
Hi,
I have 2 site collections in same tenet called Site1 & Site2.
i have requirement to pull information from Site2 and display on Site1.
Also having multiple Filter condition to get data from site2. So i am going for REST API endpoint to pull information.
To Avoid, multi time hitting server, i am planning to use REST API Batch request.
Since its is cross domain plat form, my Batch request for not working , and i am getting 403 forbidden exception.
Please share you suggestion or alternate approach to get information from another site collection using Client side scripting with batch request.
thanks in Advance.
Sugumaran Srinuvasan
解决方案Hi,
Did you get the X-RequestDigest using "/_api/contextinfo" rest api first?
The following example about get list items from another site collection using REST API with jQuery Ajax for your reference.
<script type="text/javascript" src="//code.jquery.com/jquery-1.12.4.min.js"></script> <script type="text/javascript">
(function(){ var otherSiteUrl = "http://sitecollection1/"; var listName = "TestList"; // Get form digest value of the other site collection
.ajax({ url: otherSiteUrl + "/_api/contextinfo", type: "POST", //While trying to get Context info for user POST is used as type instead of method because body is empty while //request is sent headers: { "Accept": "application/json;odata=verbose" }, success: function(contextData) { //alert(contextData.d.GetContextWebInformation.FormDigestValue);
这篇关于跨域的SharePoint REST API批处理操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!