Loading

Error 'XMLHttpRequest cannot load, No Access-Control-Allow-Origin'

Дата публикации: Oct 13, 2022
Описание

Users get error  XMLHttpRequest cannot load, No 'Access-Control-Allow-Origin' is present in Visualforce page

You may have a problem with an embedded Visualforce page for custom objects that include custom components. The page might be embedded on the standard page layout for a custom object. When that custom object record is viewed, the VF page is rendered. The page then starts polling to see when a process is complete. This polling request is failing because the request is originating from a different domain. 

For e.g. you can see that the Origin header is set to “https://na14.salesforce.com”. The request is going to “c.na14.visual.force.com” so the request fails.

Решение

The issue can be addressed using the built-in HTTP(S) Proxy. You can enable the proxy in the standard setup menu.

For Classic: Setup | Security Controls | Remote Site Settings
For Lightning: Setup | Security | Remote Site Settings

There you can add your own salesforce instance. e.g. eu1.salesforce.com (don't forget to enable https).
See more on how to Configure Remote Site Settings

In a second step you have to modify your ajax request to set url as "https://c.na1.visual.force.com/services/proxy"
The best solution is to use the fully documented HTTP Proxy service from Salesforce.

Note : If the site is inactive, CORS error is expected. Hence, ensure that the site is active.

Additional Reference:
Http Classes

Номер статьи базы знаний

000386868

 
Загрузка
Salesforce Help | Article