retrieving collection of records from an entity in dynamic crm using REST and ajax
Looking to retrieve all accounts from the account entity and show this in an alert box using an ajax call to the Service OrganizationData.svc.
This ajax call works fine with a post. as in, adding an account to the set of accounts. Retrieving all the accounts though using a GET. im getting trouble
$.ajax({
type: "GET",
contentType: "application/json; charset=utf-8",
dataType: "json",
url: "http://testCrm/MYORG/XRMServic开发者_StackOverflow中文版es/2011/OrganizationData.svc/AccountSet",
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) {
if ((data.d != null) && (data.d.length > 0)) {
alert(data.d)
}
else { alert("error!"); }
},
error: function (XmlHttpRequest, textStatus, errorThrown) {
}
});
});
I am getting an error pop up, so I'm guessing no data is being returned.
i think you should try this
change this dataType: "json"
, to dataType: "jsonp"
or
open firebug (install if you don't have done it yet) and see what error message its showing, u may need to switch to NET tab in firebug if you are making a cross-domain request, which i think you are doing.
精彩评论