locked
Need to re-write so that JQuery should be used to make Rest calls in CRM. New to this please help RRS feed

  • Question

  • SOAP.sendRequest = function (soapXml, successCallback, async) {
    debugger;
        var orgServicePath = this.orgServicePath();
        if (!async) async = true;
        var data = $.ajax({
            type: "POST",
            url: orgServicePath,
            data: soapXml,
            async: async,
            beforeSend: function (XMLHttpRequest) {
                //Specifying this header ensures that the results will be returned as XML.
                XMLHttpRequest.setRequestHeader("Accept", "application/xml, text/xml, */*");
                XMLHttpRequest.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
                XMLHttpRequest.setRequestHeader("SOAPAction", "http://schemas.microsoft.com/xrm/2011/Contracts/Services/IOrganizationService/Execute");
            },
            success: function (data, textStatus, XmlHttpRequest) {
                if (async == true) {
                    successCallback(data);
                }
                else if (async == false) {
                    return data;
                }
            },
            error: function (XmlHttpRequest, textStatus, errorThrown) {
            }
        });


        if (async == false && typeof (data) != 'undefined') {
            //var responseXml = data.responseXml;
            return data;
        }
    };

    Monday, November 10, 2014 10:52 PM

All replies

  • Hi,

    Pls dowload Odata Query Designer. http://crm2011odatatool.codeplex.com/

    After building your query using OData Query Designer you can make jquery ajax request

     jQuery.ajax({
                type: "GET",
                contentType: "application/json; charset=utf-8",
                datatype: "json",
                url: odataUri,
                cache: cacheData,
                async: isAsync,
                beforeSend: function (XMLHttpRequest) {                
    
                    //Specifying this header ensures that the results will be returned as JSON.             
                    XMLHttpRequest.setRequestHeader("Accept", "application/json");
                },
                success: function (data, textStatus, XmlHttpRequest) {
                    //implement your business code
                },
                error: function (XmlHttpRequest, textStatus, errorThrown) {
                   //handle error
                }
            });



    If you find this post helpful then please Vote as Helpful and Mark As Answer. Thanks and Regards, Polat Aydın My blog

    Tuesday, November 11, 2014 12:37 AM