javascript 在没有服务器端、silverlight、DBC 等的 SharePoint Intranet 上处理跨域的最佳方法

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7879371/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-26 01:37:40  来源:igfitidea点击:

Best way to handle Cross Domain on SharePoint Intranet w/o server side, silverlight, DBC etc

javascriptsharepointsharepoint-2010cross-domainintranet

提问by Wesley

I'm working on a Microsoft internal SharePoint site, and I need to pull in List data from a cross domain SharePoint site.

我在 Microsoft 内部 SharePoint 站点上工作,我需要从跨域 SharePoint 站点中提取列表数据。

I don't want to use Silverlight, for various reasons, and Business Data Connectivity is not possible right now.

由于各种原因,我不想使用 Silverlight,而且目前无法进行业务数据连接。

Is there a simple way to use JavaScript or something like it to accomplish this?

有没有一种简单的方法可以使用 JavaScript 或类似的东西来实现这一点?

回答by Jonathan Lonowski

"Simple?" Not exactly. Given your requirements, particularly "w/o server side," this isn't possible.

简单吗?” 不完全是。鉴于您的要求,特别是“无服务器端”,这是不可能的。

However, if you can forego that requirement, you have a few options for enabling cross-domain requests.

但是,如果您可以放弃该要求,那么您有几个选项可以启用跨域请求。

CORS

CORS

There's decent supportfor Cross-Origin Resource Sharingfor XMLHttpRequestand Microsoft's XDomainRequest. Though, this will require that the remote server include the proper headers in the response to allow your origin/domain to make the request.

体面的支持,跨来源资源共享XMLHttpRequest和微软的XDomainRequest。但是,这将要求远程服务器在响应中包含正确的标头,以允许您的源/域发出请求。

<% Response.AddHeader("Access-Control-Allow-Origin", "*") %>

JSONP

JSONP

A common option is JSONP, which loads the resource in a <script>with a callbackparameter with the name of a global function. Since JSON is based on JavaScript literals, this won't have the same browser-support issues, but the remote server will have to know how to construct the output and it's limited to GETrequests.

一个常见的选项是JSONP,它将资源加载到<script>带有callback全局函数名称的参数中。由于 JSON 基于 JavaScript 文字,因此不会有相同的浏览器支持问题,但远程服务器必须知道如何构造输出,并且仅限于GET请求。

// <script src="http://other.dom/resource?callback=loadResource"></script>

loadResource( [ {"id": 1, "name": "foo"}, {"id": 2, "name": "bar"} ] );

Server-side Proxy

服务器端代理

If the remote server you're requesting from can't (or won't) be adjusted to support cross-domain requests, you're pretty much left with making a Server-Side Proxy on your server.

如果您请求的远程服务器不能(或不会)被调整为支持跨域请求,那么您几乎只能在您的服务器上创建一个服务器端代理。

The general pattern is described at AjaxPatters.organd a number of .NET implementations can be found, including John Chapman'sand the Cross-Domain Proxyproject.

AjaxPatters.org上描述了一般模式,并且可以找到许多 .NET 实现,包括John ChapmanCross-Domain Proxy项目。

回答by Ken

You can use JQueryto get data from a SharePoint list. See this article.

您可以使用JQuery从 SharePoint 列表中获取数据。看到这篇文章。