Hi,
I am trying the following code to work, but it fails with the simply a word "error" as errorCode, readystate 0 and status 0. They both work directly in the browser, but not from my SharePoint hosted app.
You would recognize this code from the following article. Both urls for Reporting or published projects don't work.
function retrieveOData() {var restUrl = "http://con.my.com/pwa/_api/ProjectData/Projects"; // http://con.my.com/pwa/_api/ProjectServer/Projectsvar accept = "application/json; odata=verbose"; accept.toLocaleLowerCase();// Enable cross-origin scripting (required by jQuery 1.5 and later).// This does not work with Project Online. $.support.cors = true; $.ajax({ url: restUrl, type: "GET", contentType: "application/json", data: "", // Empty string for the optional data.//headers: { "Accept": accept }, beforeSend: function (xhr) { xhr.setRequestHeader("ACCEPT", accept); }, complete: function (xhr, textStatus) {// Create a message to display in the text box.
var message = "\r\ntextStatus: "+ textStatus +"\r\nContentType: "+ xhr.getResponseHeader("Content-Type") +"\r\nStatus: "+ xhr.status +"\r\nResponseText:\r\n"+ xhr.responseText;// xhr.responseText is the result from an XmlHttpRequest, which // contains the JSON response from the OData service. parseODataResult(xhr.responseText, 'e3ffe2b9-4298-4539-ba73-a62b291956f7');// Write the document name, response header, status, and JSON to the odataText control. alert(_docUrl); alert("\r\nREST query:\r\n"+ restUrl); alert(message);if (xhr.status != 200 && xhr.status != 1223 && xhr.status != 201) { alert(restUrl); } }, error: getProjectDataErrorHandler }); }function getProjectDataErrorHandler(data, errorCode, errorMessage) { alert("Error code: "+ errorCode + "\r\nError message: \r\n"+ errorMessage); }
function parseODataResult(oDataResult, currentProjectGuid) {
...
}
Maybe I am doing something seriously wrong. Please advice. Thanks,
kashif