【发布时间】:2017-03-12 10:13:08
【问题描述】:
我需要通过 REST 站点使用来自 SharePoint 2010 的数据。 我通过 ajax + Jquery 请求调用。 我的主机是 localhost,我正在尝试调用其他域的主机。
我正在尝试通过本地计算机上的打字稿项目调用共享点列表
我在我的 HEADER 中设置了跨域:
$.ajax({
type: "GET",
contentType: "application/json;charset=ISO-8859-1",
url: path,
dataType: "json",
cache: false,
headers: { 'Access-Control-Allow-Origin': '*' },
crossDomain: true,
async: false,
success: function (response) {
if (response.d.__next) {
recursive(response.d.__next);
}
},
error: function (XMLHttpRequest, textStatus, errorThrown) {
alert(errorThrown);
console.log(errorThrown);
console.log(textStatus);
console.log(XMLHttpRequest);
}
});
我在Source server WebConfig中设置了Cross-origin:
<httpProtocol>
<customHeaders>
<add name="Access-Control-Allow-Origin" value="http://localhost:50515" />
<add name="X-MS-InvokeApp" value="1; RequireReadOnly" />
<add name="Access-Control-Allow-Headers" value="Content-Type, Accept, X-Requested-With, X-File-Name"/>
<add name="Access-Control-Allow-Methods" value="GET, POST"/>
</customHeaders>
</httpProtocol>
但是这里发生了这个错误:
XMLHttpRequest cannot load http:MyLocalHost/SiteOrigin/_vti_bin/listdata.svc/person?_=1457982013329. Response for preflight has invalid HTTP status code 401send @ jquery.min.js:4
controller.js:50 DOMException:无法在“XMLHttpRequest”上执行“发送”:无法加载“http:MyLocalHost/SiteOrigin/_vti_bin/listdata.svc/person?_=1457982013329.”。(…) controller.js:51 错误
已经,感谢所有可以帮助我的人
【问题讨论】:
标签: ajax rest sharepoint-2010 xmlhttprequest typescript1.5