2

I am trying to use my javascript to make a call to a list that lives in a separate site collection. It is not working and blocks me due to CORS. Is there any way around this?

My question is different. The other post's user is asking for a request from the "internet", so outside of SharePoint. I am using an intranet and simply want to do a get request internally, but to call a different site collection to the one I'm on. My main javascript function looks something like this:

    function getJson(endpointUri, success, error) {
    $.ajax({
        url: endpointUri,
        type: "GET",
        processData: false,
        contentType: "application/json;odata=verbose",
        headers: {
            "Accept": "application/json;odata=verbose"
        },
        success: success,
        error: error
    });
}

function logError(error) {
    console.log(JSON.stringify(error));
}
Dkong
  • 395
  • 1
  • 5
  • 18

1 Answers1

0

Another site collection should be within Same Origin Policy, so you should not get problems with cross-domain.

This is not true for SharePoint. Each Site Collection is treated as a separate domain. So you have to enable CORS if you want to access a list from another SharePoint Site Collection, just as if you wanted to access content from the internet.

As both of your Site Collections are inside your intranet, it is still safe enough to use $.support.cors=true to solve your issue.

  • You are probably referring to host-named site collections? The default is path-named I think, which is SOP. We have yet to see any example URL from OP, so it's hard to tell what his setup is. I'm not sure what your example will help with, I'm guessing you refer to jQuery, but CORS is enabled via headers from server reply. – eirikb Apr 08 '16 at 08:24
  • an example url would be http://abd-dev.mysharepointsite.com

    calling

    http://anx-dev.mysharepoint.com

    – Dkong Apr 11 '16 at 20:10