简体   繁体   English

使用AJAX jQuery登录后检索Dynamics CRM中的记录

[英]Retrieving Records in Dynamics CRM after Logging in using AJAX jQuery

I can successfully reach XRMServices on ORGANIZATION_URL/XRMServices/2011/OrganizationData.svc/AccountSet?$select=AccountNumber and retrieve customer account number on a browser after logging in. However, there is an authentication service blocking this if I use AJAX. 我可以在ORGANIZATION_URL/XRMServices/2011/OrganizationData.svc/AccountSet?$select=AccountNumber上成功访问XRMServices,并在登录后在浏览器上检索客户帐号。但是,如果使用AJAX,则有一个身份验证服务将阻止此操作。 My code is as below 我的代码如下

$.ajax({
            type: "GET",
            contentType: "application/json; charset=utf-8",
            datatype: "json",
            url: ORGANIZATION_URL+ "/XRMServices/2011/OrganizationData.svc/AccountSet?$select=AccountNumber,Telephone1,Telephone2,new_CustomerDiscGroup,EMailAddress1,EMailAddress2,EMailAddress3",
            beforeSend: function (XMLHttpRequest) {
                XMLHttpRequest.setRequestHeader("Accept", "application/json");
                console.log(XMLHttpRequest);
            },
            complete: function (XmlHttpRequest) {
                console.log(XMLHttpRequest);
            },
            success: function (data, textStatus, XmlHttpRequest) {
                console.log(data);
            },
            error: function (XmlHttpRequest, textStatus, errorThrown) {
                console.log(textStatus);
            }
        });

What am I missing??? 我想念什么???

Most likely you are doing cross-site scripting error. 您很可能在执行跨站点脚本错误。 So you are opening your CRM using for example http://localhost or http://ip_number , and then in your ajax call you are using ORGANIZATION_URL which is probably different (for example http://contosocrm ). 因此,您将使用例如http:// localhosthttp:// ip_number打开CRM,然后在您的Ajax调用中使用的可能是不同的ORGANIZATION_URL(例如http:// contosocrm )。 Make sure that you are calling your ajax request with exactly the same address as you use to access CRM (or the page that is calling ajax) 确保您使用与访问CRM(或正在调用ajax的页面)完全相同的地址来调用ajax请求。

After a huge pain, here is the answer to logging in to Dynamics CRM using jQuery 经过一番痛苦之后,这是使用jQuery登录Dynamics CRM的答案

$.ajax({
    url : 'https://<Your Authentication URL for CRM>/adfs/ls',
    data : {
        UserName : '<username>',
        Password : '<password>',
        wa : 'wsignin1.0',
        wauth : 'urn:federation:authentication:windows',
        wtrealm : '<CRM Location>',
        wct : 'YYYY-MM-DDTHH:MM:SSZ'
    },
    headers : {
        Accept: 'image/jpeg, application/x-ms-application, image/gif, application/xaml+xml, image/pjpeg, application/x-ms-xbap,application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, */*','Content-Type': 'application/x-www-form-urlencoded','Access-Control-Allow-Origin' : '*'
    },
    crossDomain: true,
    dataType: 'jsonp',
    beforeSend : function(xhr){
        console.log(xhr);
    },
    complete : function(xhr){
        console.log(xhr);
    },
    success : function(xhr){
        console.log(xhr);
    },
    error : function(xhr){
        console.log(xhr);
    }
});

Hope that helps someone 希望可以帮助某人

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用odata和jquery从Dynamics Crm中的实体检索记录 - Retrieving Records From Entity in Dynamics Crm using odata and jquery Dynamics CRM:JavaScript GET请求未使用Web.Api检索记录 - Dynamics CRM: JavaScript GET request is not retrieving records using Web.Api 检索多个记录OData java脚本Microsoft Dynamics CRM - Retrieving Multiple Records OData java Scripts Microsoft Dynamics CRM 如何使用jQuery在Dynamics CRM中操作DOM - How to manipulate DOM in Dynamics CRM using jQuery Dynamics CRM 2016 Online - 使用对话框后刷新记录 - Dynamics CRM 2016 Online - Refresh record after using dialog 使用调用 HTTPRequest 的 FetchXml 查询检索 CRM Dynamics 365 版本 8.2 中的多条记录,但 HTTPRequest 将不起作用 - Retrieve multiple records in CRM Dynamics 365 version 8.2 using FetchXml query calling HTTPRequest but HTTPRequest will not work 使用多个异步Xmlhttprequests创建/更新Microsoft Dynamics CRM订单明细记录不起作用 - Using Multple Asyncronous Xmlhttprequests to Create/Update Microsoft Dynamics CRM Order Detail Records Not Working 流程运行后刷新 Dynamics crm 中的页面 - Refresh page in Dynamics crm after flow run 使用JQuery / Ajax从API检索数据 - retrieving data from API using JQuery/Ajax 使用JavaScript强制在Dynamics CRM 2011中使用SaveForm - Force a SaveForm in Dynamics CRM 2011 using JavaScript
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM