2

This question already has an answer here:

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));
}

marked as duplicate by Mike, Waqas Sarwar MVP, Eric Alexander Apr 8 '16 at 11:59

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • Please include what you have tried so far. – Mauricio Arias Olave Apr 7 '16 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 Apr 7 '16 at 21:10
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 8 '16 at 8:24
  • an example url would be abd-dev.mysharepointsite.com calling anx-dev.mysharepoint.com – Dkong Apr 11 '16 at 20:10

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