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)

cross-domain Ajax POST inside webresource

(0) ShareShare
ReportReport
Posted on by 2,379

Hi all,

I've a requirement that to call external service with AJAX POST method. This service supports CORS and working correctly from any webpage, however I get exception (Access Denied) when I try to post data inside Dynamics 365 online webresource file.

Just simple code is below;

var request = {
    "Data": "My parameter",
    "Validation": "My validation"
};


$.ajax({
    url: _myExternalServiceUrl,
    async: true,
    type: 'POST',
    data: JSON.stringify(request),
    contentType: "application/json; charset=utf-8",
    crossDomain: true,
    dataType: 'json',
    beforeSend: function (xhr) {
        $("#loadingbar").show();
    },
    complete: function () {
        $("#loadingbar").hide();
    },
    success: function (response) {
        console.log(JSON.stringify(response));
    },
    error: function (xhr, ajaxOptions, thrownError) {
        alert("exception : " + xhr.statusText);
    }
});

I think maybe it's about "POST" to cross domain, because JSONP and GET method allows crossdomain calls.

Do you have any idea, suggestion for this?

Kind regards

*This post is locked for comments

I have the same question (0)
  • Verified answer
    a33ik Profile Picture
    84,331 Most Valuable Professional on at
  • Emre GULCAN Profile Picture
    2,379 on at

    Hi Andrew,

    Thank you for your response. It looks like a tricky but probably problem solver. I discussed with my client to convert their webservice to use GET method with querystring parameters instead of POST.

    I took a quick look to your recommendation and it returns just 2 output parameters, however my external service returns complex object dataset, how can I return this from Action? I think maybe "Text" output solves my requirements and after that I parsed it inside my webresource, do you have any experience about that?

  • Verified answer
    a33ik Profile Picture
    84,331 Most Valuable Professional on at

    Hello,

    When you have to return complex object I would suggest to use plain string, serialize your object of any complexity to JSon and deserialize it on webresource side.

  • Verified answer
    ARIFNIIT Profile Picture
    1,391 on at

    Alternate option : you can create Action to call external Web API and you can call this action using JS.

  • Emre GULCAN Profile Picture
    2,379 on at

    Hi Mohammad,

    Thank you, your answer is same with Andrew's solution.

    Probably I'll try this way and use external service inside Action.

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