JS call at the front end of the web api

What to write front-end Web API has been particularly difficult problem is not that we can use CRM REST Builder ( https://github.com/jlattimer/CRMRESTBuilder ) to generate want to use CRM REST Builder

 

var req = new XMLHttpRequest();
req.open("GET", Xrm.Page.context.getClientUrl() + "/api/data/v8.2/accounts(" + parent.Xrm.Page.data.entity.getId().replace('{', '').replace('}', '') + ")?$select=accountid,address1_addressid", true);
req.setRequestHeader("OData-MaxVersion", "4.0");
req.setRequestHeader("OData-Version", "4.0");
req.setRequestHeader("Accept", "application/json");
req.setRequestHeader("Content-Type", "application/json; charset=utf-8");
req.setRequestHeader("Prefer", "odata.include-annotations=\"*\"");
req.onreadystatechange = function() {
    if (this.readyState === 4) {
        req.onreadystatechange = null;
        if (this.status === 200) {
            var result = JSON.parse(this.response);
            var accountid = result["accountid"];
            var address1_addressid = result["address1_addressid"];
        } else {
            Xrm.Utility.alertDialog(this.statusText);
        }
    }
};
req.send();

 

Guess you like

Origin www.cnblogs.com/TheMiao/p/12289210.html