jure Posted February 11, 2015 Share Posted February 11, 2015 My config.xml has the "Domain Access" set to "*". I don't have the possibility to change remote server's headers (it's an hardware device). My cross-domain XMLHttpRequest calls works well. But if i make the same calls in a web worker (created with the blob technique) they don't work anymore! Why? Is there a workaround? Thanks!I'm using this function (i'm not sure about the headers, i think they should stay in the server's response, not in the client request):myapp.ajax=function(){ var o = arguments[0]||{}, url = o.url||null, cache = o.cache||true, timeout = o.timeout||0, callback = arguments[1]||function(){} ; if(!url)return null; var myRequest = new XMLHttpRequest(); myRequest.timeout = timeout; var urlToCall=url; if(!cache){ urlToCall += urlToCall.indexOf('?')==-1 ? '?' : '&' ; urlToCall += '_=' + Date.now() ; } myRequest.onreadystatechange=function() { if (myRequest.readyState == 4) { if (myRequest.status == 200) { callback(myRequest.responseText,'success',myRequest); } else { callback(myRequest,'error',myRequest.statusText); } } } myRequest.open("GET",urlToCall,true); myRequest.setRequestHeader("Access-Control-Allow-Origin", "*"); myRequest.setRequestHeader("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept"); myRequest.setRequestHeader("Access-Control-Allow-Methods","POST, GET, OPTIONS, DELETE, PUT, HEAD"); myRequest.send(null);} Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.