Hi, I have a piece of code that I want to execute inside a HTML5 Web Worker. The code operates perfectly in Chrome, but fails in IE 11. The failure occurs on the .open call to the XMLHTTPRequest object. The error is …
“Error occured in XMLHttpRequest: ReadyState: 0 Status:0 E: Error: Access is denied.rn Msg:Access is denied.rn”
The code I’m running is as follows. The purpose of the code is simply to make a web service call and get the return. If I run the code outside of the WebWorker, it executes without issues. But as soon as I put it inside a web worker I get the access is denied error in IE11. It will however work in Chrome perfectly. Are there some IE settings I need to be aware of? I’ve investigated the cross domain stuff I’ve seen on the net and tried the various solutions I’ve found, but no joy. The offending line is xhr2.open(method, url, true);
Any ideas would be really appreciated. I’ve wasted a couple of days on this already!
Thanks,
Derek.
var worker_fn = function(e)
{
var data = e.data;
switch (data.cmd) {
case ‘start’:
var getSpecData = function (params, url) {
var xhr;
try {
function createCORSRequest(method, url) {
var xhr2 = new XMLHttpRequest();
if (“withCredentials” in xhr2) {
// Check if the XMLHttpRequest object has a “withCredentials” property.
// “withCredentials” only exists on XMLHTTPRequest2 objects.
xhr2.open(method, url, true);
} else if (typeof XDomainRequest != “undefined”) {
// Otherwise, check if XDomainRequest.
// XDomainRequest only exists in IE, and is IE’s way of making CORS requests.
xhr2 = new XDomainRequest();
xhr2.open(method, url);
} else {
// Otherwise, CORS is not supported by the browser.
xhr2 = null;
}
return xhr2;
}
var myxhr = createCORSRequest(‘POST’, url);
if (!myxhr) {
throw new Error(‘CORS not supported’);
}
myxhr.setRequestHeader(‘Content-Type’, ‘application/json; charset=utf-8’);
myxhr.setRequestHeader(‘X-Requested-With’, ‘XMLHttpRequest’);
myxhr.setRequestHeader(‘Access-Control-Allow-Origin’,’*’);
myxhr.onreadystatechange = function () {
if (myxhr.readyState == 4 && myxhr.status == 200) {
var result = JSON.parse(myxhr.responseText);
self.postMessage(result.d);
}
else if (myxhr.readyState != 1)
{
self.postMessage(‘XMLHttpRequest: ‘ + myxhr.statusText + ‘ ReadyState: ‘ + myxhr.readyState + ‘ Status:’ + myxhr.status + ‘ E: ‘ +e+’ Msg:’+e.message); }
};
myxhr.send(params);
}
catch (e) {
self.postMessage(‘Error occured in XMLHttpRequest: ‘ + xhr.statusText + ‘ ReadyState: ‘ + xhr.readyState + ‘ Status:’ + xhr.status + ‘ E: ‘ +e+’ Msg:’+e.message);
}
};
getSpecData(data.data, data.url);
break;
default:
self.postMessage(‘Unknown command: ‘ + data.msg);
};
};
var blob = new Blob([“onmessage =”+worker_fn.toString()], { type: “text/javascript” });
var worker = new Worker(window.URL.createObjectURL(blob));
worker.onmessage = function(e)
{
getFileNameSuceeded(e.data);
};
var serviceUrl = ‘
var params = ‘{“formType”:”‘ + formType + ‘”,”referenceId”:”‘ + referenceId + ‘”,”version”:”‘ + version + ‘”,”siteIdentity”:’ + siteIdentity.toJSON() + ‘}’;
worker.postMessage({‘cmd’: ‘start’, ‘url’ : serviceUrl, ‘data’ : params});