I'm working on an angular web application that must support IE10. I need to make a cross domain call to our enterprise salesforce server. In chrome (which we don't support officially, but we all develop in) that call fails because chrome makes that OPTIONS preflight call to the salesforce server, which does not support CORS.
However, IE does not make a CORS preflight, so I assumed I would have no problems making this call. But I get an "Access is Denied." error thrown from deep inside the angular code.
Further digging reveals that the specific line in angular (v1.2.21) that is failing is:
xhr.open(method, url, true); (on line 8544 if you happen to have version 1.2.21).
In looking at github, google groups, and stack overflow threads, I see that the issue might be with the way IE wants to handle cross domain requests, specifically which xhr object is being invoked to make the call.
It seems that older versions of angular had this issue, but it was addressed by adding a function prior to the xhr.open()
call to retrieve the correct XMLHttpRequest
object for the version of IE that is running:
var xhr = createXhr(method);
xhr.open(method, url, true);
forEach(headers, function(value, key) {
if (isDefined(value)) {
xhr.setRequestHeader(key, value);
}
});
So in theory, the correct xhr object is having its .open()
method called. However for me, that line throws an "Access is Denied" error.
In the links above, it seems commonly suggested that instead of using the XMLHttpRequest
object for cross domain calls, you have to use XDomainRequest()
. Thinking it was unlikely that the angular folks missed this, I tried it anyway, just manually altering the code in the angular.js file to return that object for our specific salesforce call:
var xhr;
if (url.indexOf("salesforce.com") > -1) {
xhr = new XDomainRequest();
}
else {
xhr = createXhr(method);
}
xhr.open(method, url, true);
forEach(headers, function(value, key) {
if (isDefined(value)) {
xhr.setRequestHeader(key, value);
}
});
Except now the line where the code tries to call xhr.setRequestHeader(key, value)
fails. Does anyone know what the problem is? I have a hard time believing angular doesn't have a way to deal with cross domain calls in IE, so I imagine I'm just missing something.