简体   繁体   中英

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. I'm trying to populate a CRM form with this data using some javascript (with jquery). 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. The issue is that the ajax call seems to do nothing. 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("");
        }
    });

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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