Access-Control-Allow-Origin

Jul 17, 2012 at 9:07 PM
Edited Jul 18, 2012 at 9:06 PM

I am attempting to access a SharePoint list structure located on one site farm (http://farm1.sharepoint.corp.com/sites/source/lists/listname) from a Content Editor Web Part on a Page that I have created on a personal site on another corporate farm (http://farm2.sharepoint.corp.com/sites/mysite/pages/mypage).

I am able to access and display the remote list contents when using an IE 7 browser, though cannot access the content when using an IE 8+ or Chrome browser.  the Chrome browser console reports the following error:

  • Failed to load resource: the server responded with a status of 403 (Forbidden) http://farm1.sharepoint.corp.com/sites/source/_vti_bin/Lists.asmx
  • XMLHttpRequest cannot load http://farm1.sharepoint.corp.com/sites/source/_vti_bin/Lists.asmx. Origin http://farm2.sharepoint.corp.com is not allowed by Access-Control-Allow-Origin.

My review of discussions topics around this item refer to the ensuring $.support.cors = true, which I have already done.

The code in my content Editor Web Part is:

 

<html>
<script type="text/javascript" src="../jquery/jquery-1.7.1.min.js"></script>
<script type="text/javascript" src="../jquery/jquery.SPServices-0.7.1a.min.js"></script>
<script language="javascript" type="text/javascript">

	var url = "http://farm1.sharepoint.corp.com/sites/source";

	var list = "(0E062A73-2F4E-4D9B-A5B9-509A568CBC39)"; //"GUID for Asset List"

	var fieldName1 = "Asset";						//Asset name
	var fieldName2 = "Description";			//asset Description
	var fieldName3 = "Asset_x0020_Name";		//Asset Link
	var fieldName4 = "Type_x0020_of_x0020_Asset";	//Asset Type
	var fieldName5 = "Suite_x0020_Name_x0020_A";	//Asset Suite

	var query =  "<Query></Query>";	//Pull all records

	$.support.cors = true;
	$(document).ready(function() {

		$().SPServices({
			operation: "GetListItems",
			async: false,
			webURL: url,
			listName: list,
			CAMLQuery: query,
			completefunc: function (xData, Status) {

//				Alert to test that the SPServices package is functioning
//				alert("Status of XML Sharepoint webservice: " + Status + ", \n Response from server: " + xData.responseText);
			   
				var htmlCntnt = "<B>" + list + "</B> elements:</BR>";
				htmlCntnt = htmlCntnt + "<table><tr width='800px'>";
				
				htmlCntnt = htmlCntnt + "<th width='20%'>" + fieldName1 + "</th>";
				htmlCntnt = htmlCntnt + "<th width='10%'>" + fieldName2 + "</th>";
				htmlCntnt = htmlCntnt + "<th width='40%'>" + fieldName3 + "</th>";
				htmlCntnt = htmlCntnt + "<th width='10%'>" + fieldName4 + "</th>";
				htmlCntnt = htmlCntnt + "<th width='20%'>" + fieldName5 + "</th>";
				htmlCntnt = htmlCntnt + "</tr>";
				
				//iterate through the result set
				$(xData.responseXML).SPFilterNode("z:row").each(function() {
					htmlCntnt = htmlCntnt + "<tr>";
					htmlCntnt = htmlCntnt + "<td>" + $(this).attr("ows_"+fieldName1) + "</td>";
					htmlCntnt = htmlCntnt + "<td>" + $(this).attr("ows_"+fieldName2) + "</td>";
					htmlCntnt = htmlCntnt + "<td>" + $(this).attr("ows_"+fieldName3) + "</td>";
					htmlCntnt = htmlCntnt + "<td>" + $(this).attr("ows_"+fieldName4) + "</td>";
					htmlCntnt = htmlCntnt + "<td>" + $(this).attr("ows_"+fieldName5) + "</td>";
					htmlCntnt = htmlCntnt + "</tr>";
				});
				htmlCntnt = htmlCntnt + "</table>";
				$("#pageContent").append(htmlCntnt);
			}
		});

	});

</script>
<div id="pageContent"/>
</html>

Assistance is appreciated in resolving this issue would be appreciated.

Additional Information:

Using Fidder I get the follwing:

Request Headers:

OPTIONS /sites/source/_vti_bin/Lists.asmx HTTP/1.1
Host: http://farm1.sharepoint.corp.com
Connection: keep-alive
Cache-Control: max-age=0
Access-Control-Request-Method: POST
Origin: http://farm2.sharepoint.corp.com
User-Agent: Mozilla/5.0 (Windows NT 6.0) AppleWebKit/536.11 (KHTML, like Gecko) Chrome/20.0.1132.57 Safari/536.11
Access-Control-Request-Headers: origin, content-type, accept
Accept: */*
Referer: http://farm1.sharepoint.corp.com/sites/mysite/pages/JQuerySPServicesSamples.aspx 
Accept-Encoding: gzip,deflate,sdch
Accept-Language: en-US,en;q=0.8
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3

 Responce Headers:

HTTP/1.1 403 Forbidden
Content-Length: 1758
Content-Type: text/html
Server: Microsoft-IIS/6.0
MicrosoftSharePointTeamServices: 12.0.0.6421
X-Powered-By: ASP.NET
Date: Wed, 18 Jul 2012 20:34:36 GMT

 

Feb 5, 2013 at 5:46 AM
Hi! Were you able to solve this problem? If yes, how? I'm having the same issue.
Feb 26, 2013 at 6:36 PM
Hi!

i'm also having this problem, any news? anyone have been able to solve this?
Feb 26, 2013 at 7:14 PM
I'm having a similar issue when trying to access some methods using http://site/subsite instead http://site.domain.com/subsite.
Only solved accessing entire (and same) domain or changing AAM on SharePoint to support both URLs.

More details: http://spservices.codeplex.com/discussions/434120

If I have some news, I'll report here!
Coordinator
Feb 26, 2013 at 7:40 PM
Note that the cross-domain thing isn't an SPServices problem, but security baked into the browsers.

M.
Mar 15, 2013 at 9:59 PM
Okay... Yah this makes sense with my other problem.