Skip to content

Instantly share code, notes, and snippets.

@swapnilshrikhande
Created November 11, 2014 11:59
Show Gist options
  • Save swapnilshrikhande/d1e018a3ebf3d56252db to your computer and use it in GitHub Desktop.
Save swapnilshrikhande/d1e018a3ebf3d56252db to your computer and use it in GitHub Desktop.
CORS_using_SF_PROXY
var credential = ' OAuth ' + "<session id of target org >"; // native VF function
var apiUrl = "https://ap1.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://na9.salesforce.com/services/proxy",
contentType: 'application/json',
cache: false,
success : function(response) {
console.log("result",response);
},
error : function(response) {
console.log("Failed",response);
},
dataType: "json",
beforeSend: function(xhr) {
xhr.setRequestHeader('SalesforceProxy-Endpoint', apiUrl);
xhr.setRequestHeader("Authorization", credential);
xhr.setRequestHeader('X-User-Agent', 'MyClient');
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment