简体   繁体   English

MS CRM 2011 JavaScript使用JSON服务

[英]MS CRM 2011 javascript consuming JSON service

I have a JSON web service running that I can hit from a browser and get some simple data. 我正在运行一个JSON Web服务,可以从浏览器中访问它并获取一些简单数据。 I'm trying to populate a CRM form with this data using some javascript (with jquery). 我正在尝试使用一些JavaScript(使用jquery)用此数据填充CRM表单。 The script fires on form load, and here's what it looks like: 该脚本在加载表单时触发,如下所示:

function execute()
{
alert("start");

$.ajax({
  url: "http://myFancyService",
  data: "{}",
  dataType: "json",
  failure: function (msg) {
    alert("didn't work");
  },
  success: function (success) {
    alert("worked");
  }
});

alert("end");
}

I have added jQuery 1.9.1 as a web resource, and I call "isNaN" on form load. 我已将jQuery 1.9.1添加为Web资源,并在表单加载时调用“ isNaN”。 The issue is that the ajax call seems to do nothing. 问题在于,ajax调用似乎无济于事。 I see the "start" alert, and then the "end" alert, and nothing in between. 我看到“开始”警报,然后看到“结束”警报,两者之间什么也没有。 What am I missing? 我想念什么?

There are missing elements in your call, check this example code: 您的通话中缺少元素,请查看以下示例代码:

$.ajax({ 
        type: "POST",
        contentType: "application/json; charset=utf-8",
        datatype: "json",
        url: Xrm.Page.context.getServerUrl() + "/XRMServices/2011/OrganizationData.svc/AccountSet",
        data: "{}",
        beforeSend: function (XMLHttpRequest) {
            XMLHttpRequest.setRequestHeader("Accept", "application/json");
        },
        success: function (data, textStatus, XmlHttpRequest) {
            alert("");
        },
        error: function (XMLHttpRequest, textStatus, errorThrown) {
            alert("");
        }
    });

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM