如何在同一Web应用程序中将数据从SharePoint主机头网站集获取到另一个主机头网站集 [英] How to get data from SharePoint host header site collection to another host header site collection with in same Web application
问题描述
使用Rest API从SharePoint主机标头网站集中的数据获取到另一个主机标头网站集中的数据时,我们会收到401未经授权的错误.请帮忙.
While Getting data from SharePoint host header site collection to another host header site collection using rest API we are getting 401 unauthorized error. please help.
$(document).ready(function(){
getMarqueeListItem();
});
//当用户单击读取按钮时发生
函数getMarqueeListItem(){
var listName ="CorpCommunication";
var url ="http://cph.vconnect.com";
getListItems(listName,url,function(data){
var项目= data.d.results;
alert(items.length);
},函数(数据){
marquee_list.empty();
alert(糟糕,发生了错误.请重试");
});
}
//读取操作
//listName:要从中获取项目的列表的名称
//siteurl:列表所在的网站的网址.
//成功:如果调用为sucesfull,则执行的函数
//失败:如果调用失败执行的函数
函数getListItems(listName,siteurl,成功,失败){
$ .ajax({
url:siteurl +"/_ api/web/lists/getbytitle('" + listName +"')/items',
方法:"GET",
标头:{"Accept":"application/json; odata = verbose" },
快取:false,
成功:功能(数据){
成功(数据);
},
错误:函数(数据){
失败(数据);
}
});
}
$(document).ready(function () {
getMarqueeListItem();
});
// occurs when a user clicks the read button
function getMarqueeListItem() {
var listName = "CorpCommunication";
var url = "http://cph.vconnect.com";
getListItems(listName, url, function (data) {
var items = data.d.results;
alert(items.length);
}, function (data) {
marquee_list.empty();
alert("Ooops, an error occured. Please try again");
});
}
// READ operation
// listName: The name of the list you want to get items from
// siteurl: The url of the site that the list is in.
// success: The function to execute if the call is sucesfull
// failure: The function to execute if the call fails
function getListItems(listName, siteurl, success, failure) {
$.ajax({
url: siteurl + "/_api/web/lists/getbytitle('" + listName + "')/items",
method: "GET",
headers: { "Accept": "application/json; odata=verbose" },
cache: false,
success: function (data) {
success(data);
},
error: function (data) {
failure(data);
}
});
}
错误:
推荐答案
要进行跨域Rest API调用,必须添加"Access-Control-Allow-Origin"在Web.config中使用PowerShell脚本:
To make Cross-Domain Rest API call, it's necessary to add "Access-Control-Allow-Origin" in web.config using PowerShell script:
谢谢
最好的问候
这篇关于如何在同一Web应用程序中将数据从SharePoint主机头网站集获取到另一个主机头网站集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!