我正在尝试使用Ajax调用来获取CRM数据。数据正在返回' d'和'结果'属性,但我无法在客户端获得它。它说ajaxdata.d未定义。
示例Ajax调用:
var context = Xrm.Page.context;
var serverUrl = context.getClientUrl();
var ODATA_ENDPOINT = context.prependOrgName("/xRMServices/2011/OrganizationData.svc");
var filter = "?&$select=cc_TypeID,cc_customentityId,cc_anotherAttribute&$filter=cc_TypeID eq '2'";
var odataUri = ODATA_ENDPOINT + "/cc_customentitySet" + filter;
console.log("odataUri: " + odataUri);
//Asynchronous AJAX function to Retrieve a CRM record using OData
$.ajax({
type: "GET",
contentType: "application/json; charset=utf-8",
datatype: "json",
url: odataUri,
async: false,
beforeSend: function (XMLHttpRequest) {
//Specifying this header ensures that the results will be returned as JSON.
XMLHttpRequest.setRequestHeader("Accept", "application/json");
},
success: function (ajaxdata, textStatus, XmlHttpRequest) {
//console.log("cc_campaignSynch.htm > ready > $.ajax success: " + data);
debugger;
},
error: function (XmlHttpRequest, textStatus, errorThrown) {
console.log("cc_campaignSynch.htm > ready > $.ajax error: " + XmlHttpRequest.responseText);
}
});
});
返回的数据快照:
更新了快照(使用了JSON.parse):
答案 0 :(得分:3)
可能是什么都没有,但尝试改变"数据类型"到" dataType"
答案 1 :(得分:0)
要强制jQuery magic 工作并识别数据类型,请尝试使用HEADER: "Content-Type: application/json"
发送回复。