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

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

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

(0) ShareShare
ReportReport
Posted on by

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

I have the same question (0)
  • Erry Handani Profile Picture
    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.

  • Suggested answer
    sandeepstw Profile Picture
    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

  • Suggested answer
    Nithya Gopinath Profile Picture
    17,078 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.

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…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
HR-09070029-0 Profile Picture

HR-09070029-0 2

#1
UllrSki Profile Picture

UllrSki 2

#3
ED-30091530-0 Profile Picture

ED-30091530-0 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans