简体   繁体   English

使用SPServices + jQuery的CORS

[英]CORS with SPServices + jQuery

I need to access from a different domaine on a mobile a sharepoint list. 我需要从移动设备上的其他域访问共享点列表。 Here is my code, a simple get request : 这是我的代码,一个简单的get请求:

$.support.cors = true;

$(function() {
$().SPServices({
    operation: "GetListItems",
    webURL: "http://myurl.com/project/",
    listName: "PM-Registration",
    CAMLQuery: '<Query></Query>',
    error: function (xhr, message, error) {
          alert('error : ' + error);
    },
    completefunc: function (xData, status) {
        alert('Status: '+status+' xdata: ' + xData.statusText);
        alert('RESPONSE: ' + xData.responseText);
    }
});
});

The problem seems to be CORS blocking the request, but I normally enable it before. 问题似乎是CORS阻止了该请求,但是我通常在以前启用了它。 It works perfectly with Chrome if I use the command : --args --disable-web-security, and with Safari desktop, but not with Firefox and Safari iOS... I got the error on Chrome without disabling web security : 如果我使用以下命令,它可以完美地与Chrome配合使用:--args --disable-web-security,以及Safari桌面,但不适用于Firefox和Safari iOS ...我在没有禁用网络安全性的情况下在Chrome上看到了错误:

No 'Access-Control-Allow-Origin' header is present on the requested resource

Am I missing something ? 我想念什么吗? I guess it is a client side problem as it works with Chrome without web security and Safari Desktop 我猜这是一个客户端问题,因为它可以与没有网络安全性和Safari桌面的Chrome一起使用

I will provide an answer to my question. 我将回答我的问题。

Even if it work on IE and with specific command on Chrome, this is a security issue set on the server side, only the server can change it by modifing the Access-Control-Allow-Origin 即使它可以在IE上运行并且在Chrome上具有特定命令,这也是服务器端设置的安全问题,只有服务器才能通过修改Access-Control-Allow-Origin对其进行更改

I didn't find a workaround to avoid this CORS problem from the client side. 我没有找到解决方法来从客户端避免此CORS问题。 My solution was to move my HTML page on the same domain as my SharePoint. 我的解决方案是将HTML页面移到与SharePoint相同的域上。 I have now my SharePoint : www.mysharepoint.com , and my mobile webapp www.mysharepoint.com/mobile/index.html 我现在拥有SharePoint: www.mysharepoint.com和移动网络应用程序www.mysharepoint.com/mobile/index.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM