I'm calling REST API from javascript. The API call fails and gives the following two errors
SEC7123: Request header loginrequestcorrelationid was not present in the Access-Control-Allow-Headers list.
SCRIPT7002: XMLHttpRequest: Network Error 0x80070005, Access is denied.
Below is my code:
$.ajax({
url: "mycrm.api.crm.dynamics.com/.../products(FCF2FCA4-8337-E811-A952-000D3A3026D6)$select=name,description,price",
type: "GET",
contentType: "application/json; charset=utf-8",
dataType: "jsonp",
crossDomain: true,
xhrFields: {
cors: true
},
beforeSend: function (XMLHttpRequest) {
XMLHttpRequest.setRequestHeader("OData-MaxVersion", "4.0");
XMLHttpRequest.setRequestHeader("OData-Version", "4.0");
XMLHttpRequest.setRequestHeader("Accept", "application/json");
XMLHttpRequest.setRequestHeader("Prefer", "odata.include-annotations=\"OData.Community.Display.V1.FormattedValue\"");
},
success: function (data, textStatus, xhr) {
alert(data.name)
},
error: function (xhr, textStatus, errorThrown) {
alert(textStatus + " " + errorThrown);
}
})
How do I fix this issue?