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));
}
2
  • Please include what you have tried so far. Commented Apr 7, 2016 at 21:08
  • Another site collection should be within Same Origin Policy, so you should not get problems with cross-domain. Make sure it's the same schema (http/https), host (including subdomain) and port.
    – eirikb
    Commented Apr 7, 2016 at 21:10

1 Answer 1

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.

2
  • 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
    Commented Apr 8, 2016 at 8:24
  • an example url would be abd-dev.mysharepointsite.com calling anx-dev.mysharepoint.com
    – Dkong
    Commented Apr 11, 2016 at 20:10

Not the answer you're looking for? Browse other questions tagged or ask your own question.