Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Web and WebWorks Development

Reply
Contributor
Posts: 23
Registered: ‎12-27-2010
My Device: 8900, 9630

XMLHttpRequest send method fails in a web worker?

I tried to use web worker thread to call a web service via XMLHttpRequest. When calling 'send' method the app crashes.

What can be the reason?

 

Can we use web workers to call web services via XMLHttpRequest?

 

Thanks.

Retired
Posts: 3,708
Registered: ‎10-16-2008
My Device: Z10
My Carrier: Rogers

Re: XMLHttpRequest send method fails in a web worker?

Hi kalan,

 

Can you post up your BlackBerry OS version and maybe some sample JavaScript that replicates the problem?

Tim Neil
Director, Application Platform & Tools Product Management
Follow me on Twitter
Contributor
Posts: 23
Registered: ‎12-27-2010
My Device: 8900, 9630

Re: XMLHttpRequest send method fails in a web worker?

[ Edited ]

I'm using this code with playbook.

 

I call 'myWebworker' when a button press event occurs,

function myWebworker() {	
	var worker = new Worker('Scripts/worker.js');
	worker.onmessage = function() {
	    alert("Worker says: ");
	};
	worker.postMessage(); 
}

 

is the main code and following is the worker.js code.

onmessage = function() {
	
	var xmlHttp = new XMLHttpRequest();
	url = "myURL";
	xmlHttp.open('POST', url, false);
	xmlHttp.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
	var param = "myXML";
	xmlHttp.onreadystatechange = function() {
		postMessage();
		if (xmlHttp.readyState == 4 && xmlHttp.status == 200) {
		   var node = getStrNodeValues(xmlHttp.responseXML
					.getElementsByTagName("Status"));
		   var authToken = getStrNodeValues(xmlHttp.responseXML
					.getElementsByTagName("Token"));
			
		}
	};	
	xmlHttp.send(param);
	
};

When I call 'xmlHttp.send(param)',  the app crashes.

 

Otherwise the worker works perfectly. but can't call the web service.

 

Thanks.

 

 

Retired
Posts: 3,708
Registered: ‎10-16-2008
My Device: Z10
My Carrier: Rogers

Re: XMLHttpRequest send method fails in a web worker?

I take it this is in a WebWorks app?

 

If so, have you white listed the URL of the AJAX call in your config.xml file?

Tim Neil
Director, Application Platform & Tools Product Management
Follow me on Twitter
Contributor
Posts: 23
Registered: ‎12-27-2010
My Device: 8900, 9630

Re: XMLHttpRequest send method fails in a web worker?

Yes sir,

 

This works perfectly without using a worker.

 

Thanks.

Retired
Posts: 3,708
Registered: ‎10-16-2008
My Device: Z10
My Carrier: Rogers

Re: XMLHttpRequest send method fails in a web worker?

From our investigation we have found that the same code in Safari and Chrome will produce a reuslt of 405.  This only happens if you try and use POST instead of GET in your AJAX call from a worker.  I'm not sure if this is simply a WebKit bug, or a security measure.

 

However, the signature of the crash is definately a bug and it has been submitted to our Browser team to ensure that it gets fixed.

Tim Neil
Director, Application Platform & Tools Product Management
Follow me on Twitter