I'm doing a very simple REST Get to a list of broadcast messages on the web application that serves as our "intranet portal" from the web application we use for team site collections. Both web applications are in the same domain (names changed to protect the innocent and my job):
- intranet.domain.com
- teamsites.domain.com
Here's a sample of the code I'm using:
$(function(){ var api = new ApiHelper('https://intranet.domain.com'); var options = { list:'Broadcasts', op:'Items', params:{ 'orderby':'Created desc', 'top':10 } } api.getListData(options).done(function(data){ console.log(data); }); }); window.ApiHelper = function(webUrl){ this.webUrl = webUrl; } ApiHelper.prototype.execute = function(relativeUrl){ var fullUrl = this.webUrl + "/_api" + relativeUrl; var executeOptions = { url: fullUrl, method: 'GET', dataType: "json", headers: { 'accept':'application/json;odata=verbose', 'content-type':'application/json;odata=verbose' } }; return $.ajax(executeOptions); } ApiHelper.prototype.getListData = function(options){ //Set the base endpoint Url. var executeUrl = "/web/lists/getByTitle('"+options.list+"')"; if(options.op == 'All'){return this.execute(executeUrl).then(function(data){if(data.d){return data.d;}else{throw "Something bad happened..."}}); }else if(options.op == 'Id'){executeUrl+='/Id';return this.execute(executeUrl).then(function(data){if(data.d){return data.d.Id;}else{throw "Something bad happened..."}}); }else if(options.op == 'Forms' || options.op == 'Views' || options.op == 'WorkflowAssociations'){ executeUrl+=options.op; return this.execute(executeUrl).then(function(data){ if(data.d && data.d.results){ return new QueryResults(data.d.results); } else { throw "Something bad happened..."; } }); }else{ executeUrl+='/items'; //If there's a parameter object, then add the dollar signs, turn it into a string, and add it to the URI. if(options.params){ params = options.params; var key; for(key in params){ if(params.hasOwnProperty(key)){params['$'+key] = params[key];delete params[key];} } queryString = decodeURIComponent($.param(params)); executeUrl+='?'+queryString; } return this.execute(executeUrl).then(function(data){ if(data.d && data.d.results){ return new QueryResults(data.d.results); } else { throw "Something bad happened..."; } }); } } Using this, I get a cross origin failure every time when it's run from the teamsites.domain.com web application. Which shouldn't happen, because both web apps are in the same domain... right?
I realize this is very similar to questions that have been asked a few times before, so let me start by saying a couple of things up front:
- Using SP.AppContext in the endpoint URL continues to give me the cross origin failure as well.
- I've tried using the CORS library, and that gives me one of these:

If I click Fix It, I get taken to an error page on the intranet webapp for a page that doesn't exist. - According to research, the primary suggestion is that this is because my intranet and teamsites web applications are "in different IE security zones". That seems like it can't be my case, because 1.) they're both in the .domain.com domain, and I have a wildcard in my list of intranet sites in IE's security options for that domain and 2.) it's my understanding that Chrome and Firefox don't do security zones and I get the same issues in those browsers.
- I've tried doing... whatever the hell it is they're suggesting here, but I'm not sure what I'm supposed to do with that app page I create.
Additional information:
- We're SP2013 on premise. Our intranet web application has not been visually upgraded yet, owing to an immense amount of ill advised (and not controlled by my group) customization to the UI there. teamsites is upgraded.
- I have a few applications currently using REST endpoints that are running out of the intranet web application and getting data from the teamsites web application without issue. Or, if they are causing problems, I haven't heard them yet.