Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

Dynamics crm : Cross - origin Error using javascript call API

Posted on by 5

Hello community ,

Actually I am trying to call an externel rest api that 's deployed in the same server as CRM ( with a different port ) using javascript 

CRM url : http://server:5555/organisation

Api url : http://server:9091/operation/id

here is my code 

{
var req = new XMLHttpRequest();
req.open("GET", url, true);
req.setRequestHeader("Accept", "application/json");
req.setRequestHeader("Content-Type", "application/json; charset=utf-8");
req.send();
req.onreadystatechange = function() {
if (this.readyState === 4) {
this.onreadystatechange = null;
if (this.status === 200) {
// do something ;
}  } }; }

But i get this following error  : 

Access to XMLHttpRequest at Api url from origin 'http://server:5555' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.

Does any one had already faced this kind of issue ??Or have any workaround ? 

Please let me Know !!

Ps: I work on CRM 2015 on premise

*This post is locked for comments

  • Shaminderpal Singh Profile Picture
    Shaminderpal Singh 1,565 on at
    RE: Dynamics crm : Cross - origin Error using javascript call API

    That's not an ideal solution. CORS is used to prevent cross origin attacks and disabling it at browser level will make other applications vulnerable and prone to security attacks and also it will only work in IE and not other browsers.

  • Verified answer
    Jamil Lamyae Profile Picture
    Jamil Lamyae 5 on at
    RE: Dynamics crm : Cross - origin Error using javascript call API

    Thanks a lot for your response I really appreciate it

    I activate the CROSS DOMAIN for IE from option tools and it works Fine for me 

  • Suggested answer
    Shaminderpal Singh Profile Picture
    Shaminderpal Singh 1,565 on at
    RE: Dynamics crm : Cross - origin Error using javascript call API

    Hi,

    You need to specify crm url as accsess origin pass in your web api.

    Refer this-docs.microsoft.com/.../enabling-cross-origin-requests-in-web-api

    -Shaminder

  • Verified answer
    gdas Profile Picture
    gdas 50,085 on at
    RE: Dynamics crm : Cross - origin Error using javascript call API

    Hi ,

    Try to check below -

    - Add the external server name in the local host file .

    - Make sure you are allowing CORS  while sending request.

    - Add the URL in browser trusted sites.

    - Enable external data-source access.

     www.webdavsystem.com/.../cross_origin_requests

    You can also follow my answer here  -

    community.dynamics.com/.../281764

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,214 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans