the issue can be addressed using the built-in HTTP(S) Proxy.
You can enable the proxy in the standard setup menu:
Setup -> Security Control -> Remote Sites / Remote Proxy Settings
Salesforce Setup Menu
There you can add your own salesforce instance. e.g. eu1.salesforce.com (don't forget to enable https)
In a second step you have to modify your ajax request:
var credential = ' OAuth ' + '{!GETSESSIONID()}'; // native VF function
var apiUrl = "https://na1.salesforce.com/services/data/v26.0/chatter/users/me";
$.ajax({
type: "GET",
// for community pages, use whole community url including path, e.g.
// https://logan.blitz01.t.force.com/customers/services/proxy.
url: "https://c.na1.visual.force.com/services/proxy",
contentType: 'application/json',
cache: false,
success : function(response) {
alert("result" + response);
},
error : function(response) {
alert("Failed" + response);
},
dataType: "json",
beforeSend: function(xhr) {
xhr.setRequestHeader('SalesforceProxy-Endpoint', apiUrl);
xhr.setRequestHeader("Authorization", credential);
xhr.setRequestHeader('X-User-Agent', 'MyClient');
}
});
Sources: https://trailhead.salesforce.com/modules/visualforce_fundamentals , https://gist.github.com/henriquez/3146782