Jump to content

Cordova, cross-domain ajax works but not in a web worker


jure
 Share

Recommended Posts

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);

}

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...