1

I get a cross origin error when I do an AJAX call, and am wondering if thereĀ“s a way to solve that. Thanks!

  • You may need to provide more information, platform you are using, is it visual force, another website, etc. Also any code snippets that are relevant would assist in an answer being given. Otherwise your question may be closed for being unclear – Eric Dec 17 '14 at 15:30
2

The use of CORS (Cross-Origin Resource Sharing) is a good way to deal with the limitations around cross-origin requests.

CORS is a W3C recommendation that enables Web browsers to request resources from origins other than their own (cross-origin requests). For example, using CORS, a JavaScript script at https://www.example.com could request a resource from https://www.salesforce.com.

With Winter '15 Salesforce added CORS support to the Chatter REST API. You can read more about it here: Winter '15 Release Notes: CORS

James Ward has also created a proxy that adds the CORS headers to Salesforce's REST APIs here: Salesforce CORS Proxy and he has written a blog post about it here: Cross-Origin Resource Sharing (CORS) for Salesforce.com

|improve this answer|||||
2

You cannot use REST API directly. You need to have some proxy page which will set headers. Normally we use "ForceTK" library to route all request to proxy page.

Here are some articles by pat -

https://developer.salesforce.com/blogs/developer-relations/2014/12/ringing-changes-force-com-javascript-rest-toolkit.html

https://developer.salesforce.com/blogs/developer-relations/2013/06/calling-the-force-com-rest-api-from-visualforce-pages-revisited.html

Example of using ForceTk using Nodejs

https://github.com/JitendraZaa/SOQLBuilder

https://github.com/JitendraZaa/ToolingAPI30Min-AceEditor

|improve this answer|||||

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