Skip to main content

Notifications

Microsoft Dynamics CRM (Archived)

Failed to execute 'send' on 'XMLHttpRequest': Failed to load

Posted on by Microsoft Employee

Hello,

Here I'm fetching data using javascript FetchXML. and It works fine in an unmanaged package but it gives me an error in a managed package.

function getAPIRecordsByFetchXML() {
    try {

        var entityNameApi = "accounts";
        var fetchData = '<fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="false"><entity name="account"><attribute name="name" /><attribute name="primarycontactid" /><attribute name="telephone1" /><attribute name="accountid" /><order attribute="name" descending="false" /><filter type="and"><condition attribute="name" operator="eq" value="Account1" /></filter></entity></fetch>';
        var data;
        var serverUrl = "abc123.crm.dynamics.com";
        var req = new XMLHttpRequest();
        req.open("GET", serverUrl + "/api/data/v8.0/" + entityNameApi + "?fetchXml=" + fetchData, false);
        req.setRequestHeader("OData-MaxVersion", "4.0");
        req.setRequestHeader("OData-Version", "4.0");
        req.setRequestHeader("Accept", "application/json");
        req.setRequestHeader("Prefer", "odata.include-annotations=\"OData.Community.Display.V1.FormattedValue\"");

        req.onreadystatechange = function () {
            if (this.readyState == 4) {
                req.onreadystatechange = null;
                if (this.status == 200) {
                    data = JSON.parse(this.response);
                }
                else {
                    var error = JSON.parse(this.response).error;
                    alert(error.message);
                }
            }
        };
        req.send();
        return data;
    } catch (e) {
        alert(e.message);
    }
}


Error:
Failed to execute 'send' on 'XMLHttpRequest': Failed to load 'https://abc123.crm.dynamics.com/api/data/v8.0/accounts?fetchXml=%3Cfetch%20version=%221.0%22%20output-format=%22xml-platform%22%20mapping=%22logical%22%20distinct=%22false%22%3E%20%20%3Centity%20name=%22account%22%3E%20%20%20%20%3Cattribute%20name=%22name%22%20/%3E%20%20%20%20%3Cattribute%20name=%22primarycontactid%22%20/%3E%20%20%20%20%3Cattribute%20name=%22telephone1%22%20/%3E%20%20%20%20%3Cattribute%20name=%22accountid%22%20/%3E%20%20%20%20%3Corder%20attribute=%22name%22%20descending=%22false%22%20/%3E%20%20%20%20%3Cfilter%20type=%22and%22%3E%20%20%20%20%20%20%3Ccondition%20attribute=%22name%22%20operator=%22eq%22%20value=%22Account1%22%20/%3E%20%20%20%20%3C/filter%3E%20%20%3C/entity%3E%3C/fetch%3E'



Please suggest me how to solve this error?

*This post is locked for comments

  • Suggested answer
    Nithya Gopinath Profile Picture
    Nithya Gopinath 17,074 on at
    RE: Failed to execute 'send' on 'XMLHttpRequest': Failed to load

    Hi Chaaya Patel,

    The FetchXML needs to be in a format usable by the Web API service endpoint.

    See: https://www.hbs.net/blog/march-2017/using-fetchxml-in-web-api-queries-via-javascript-f

    Hope this helps.

  • Suggested answer
    sandeepstw Profile Picture
    sandeepstw 4,601 on at
    RE: Failed to execute 'send' on 'XMLHttpRequest': Failed to load

    Hi,

    You are posting as "Get" Method, I think that is wrong use post method. Follow this -

    alexanderdevelopment.net/.../fetchxml-jquery-in-a-dynamics-crm-2011-web-resource

  • Erry Handani Profile Picture
    Erry Handani 95 on at
    RE: Failed to execute 'send' on 'XMLHttpRequest': Failed to load

    Hi,

    Have you checked the url if it's pointing to the correct url? Also, make sure you have the same entity & attributes.

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!

Community AMA December 12th

Join us as we continue to demystify the Dynamics 365 Contact Center

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,149 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans