Announcements
Hi everyone,
Thank you for helping in advance,
I got an error when debugging my JavaScript code
"Failed to load resource: the server responded with a status of 404 (Not Found)"
on the line: "xmlHttpRequest.send();"
full code:
executeRequest: function (request) {
var xmlHttpRequest = new XMLHttpRequest();
var response = null;
xmlHttpRequest.open("GET", OrgDataService.getRESTUrl() + request, false);
xmlHttpRequest.setRequestHeader("Accept", "application/json");
xmlHttpRequest.setRequestHeader("Content-Type", "application/json; charset=utf-8");
xmlHttpRequest.send();
return xmlHttpRequest.responseText;
},
getRESTUrl: function () {
var serverUrl = Xrm.Page.context.getClientUrl();
return serverUrl.substring(serverUrl.lastIndexOf("/")) + "/xrmservices/2011/organizationdata.svc";
}
Thank you again!
*This post is locked for comments
Hi @sartraj,
I am also facing the same issue,may I please know what you exactly passing in your Odata_query?
Thanks
Prashant Verma
thank you for your code!
thank you for your reply!
I suggest installing www.fiddler2.com and looking at the request that is being sent and causing the 404 - it is most likely to be that you have the incorrect entity set name - e.g. it should be AccountSet for accounts.
Hi Chris,
Try the below code, just pass the Odata query which you want to execute to the method and get back the result.
function ODataCall(oData_query)
{
var _result = null;
var _serverUrl = Xrm.Page.context.getClientUrl();
var _oDataSelect = _serverUrl + "/XRMServices/2011/OrganizationData.svc/" + oData_query;
var _retrieveReq = new XMLHttpRequest();
_retrieveReq.open("GET", _oDataSelect, false);
_retrieveReq.setRequestHeader("Accept", "application/json");
_retrieveReq.setRequestHeader("Content-Type", "application/json;charset=utf-8");
_retrieveReq.onreadystatechange = function ()
{
if (_retrieveReq.readyState == 4) {
if (_retrieveReq.status == 200) {
var _retrieved = JSON.parse(_retrieveReq.responseText).d;
if (_retrieved.results.length > 0) {
_result = _retrieved.results[0];
}
}
}
};
_retrieveReq.send();
return _result;
}
Let me know if you are still not able to perform Odata call, thanks.
Sartaj
André Arnaud de Cal...
293,727
Super User 2025 Season 1
Martin Dráb
232,714
Most Valuable Professional
nmaenpaa
101,158
Moderator