web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

CRM 365 Portals-No 'Access-Control-Allow-Origin' header is present on the requested resource.

(0) ShareShare
ReportReport
Posted on by

Hi,

I am trying to update a record from CRM 365 portals on a custom Button Click "Search" using Jquery Odata call. I am getting following error :

"XMLHttpRequest cannot load xyz.crm.dynamics.com/.../ylwf_xyzentitySet(guid'ce2e2bc9-5dd3-e611-9400-0003ff813809'). Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'xyz.microsoftcrmportals.com' is therefore not allowed access. The response had HTTP status code 400."

Please help me how to resolve this. 

Please find below code :

$(document).ready(function () {
$(".deactivate-link btn-default btn").click(function (event) {
alert(event.isDefaultPrevented()); event.preventDefault(); alert(event.isDefaultPrevented()); alert('success');
}); $("#custom").click(function () {
alert("Hello"); $.support.cors = true; var entity = {};
entity.ylwf_lfe_SendEmails = true;

$.ajax({
type: "POST",
crossDomain: true,
contentType: "application/json; charset=utf-8",
datatype: "json",
url: "xyz.crm.dynamics.com/.../ylwf_xyzentitySet(guid'ce2e2bc9-5dd3-e611-9400-0003ff813809')",
data: JSON.stringify(entity),
beforeSend: function (XMLHttpRequest) {
XMLHttpRequest.setRequestHeader("Accept", "application/json");
XMLHttpRequest.setRequestHeader("X-HTTP-Method", "MERGE");
},
async: true,
success: function (data, textStatus, xhr) {
//Success - No Return Data - Do Something
},
error: function (xhr, textStatus, errorThrown) {
alert(textStatus + " " + errorThrown);
}
});
});
});

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Community Member Profile Picture
    on at

    Im under the impression that you are using online where you have no ability to add custom headers via the web.config or IIS.

    To get around this you need to to use JSONP;

    $.ajax({
      type:     "GET",
      url:      "URL",
      dataType: "jsonp", //make sure this is set
      success: function(data){
        console.log(data);
      }
    });
  • Suggested answer
    Nadeeja Bomiriya Profile Picture
    6,804 on at

    Hi Vinay017,

    I am not sure if this is the best way to implement the requirement from security point of view.  How do you pass user credentials?

    Did you try other supported methods?

    community.adxstudio.com/.../entity-form-action-configuration

  • Suggested answer
    JohnAnonymous Profile Picture
    5,241 on at

    This is no issue with your code but a browser security measure to not allow calls to other domains. For an explanation on CORS, please review this document: developer.mozilla.org/.../Access_control_CORS

    And there are two other things:

    • You are calling CRM from the context of a portal. In that scenario, you are not authenticated to CRM and there's no secure way to do so, other than registering an app to the Azure AD.
    • And you are callen the 'old' and deprecated endpoint. That endpoint is not accessibel from outside CRM.
  • Community Member Profile Picture
    on at

    Thanks everyone for your suggestions.  I am able to make it work in IE9 by enabling "Access data sources across domains" for Internet and Trusted Sites  please find below screen shots.

    4428.Capture.JPG

  • Suggested answer
    JohnAnonymous Profile Picture
    5,241 on at

    Hi Vinay017,

    Good if this works for you. But IE9 is not supported anymore and this will be a per user configuration. I'm assuming when you talk about portals, these are public facing and you would have to instruct all your users to use IE9 and set this setting.

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans