03-01-2011 06:02 AM
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.
03-01-2011 01:58 PM
Hi kalan,
Can you post up your BlackBerry OS version and maybe some sample JavaScript that replicates the problem?
03-02-2011 12:41 AM - edited 03-02-2011 12:44 AM
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.
03-02-2011 07:22 AM
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?
03-02-2011 02:10 PM
Yes sir,
This works perfectly without using a worker.
Thanks.
03-02-2011 03:50 PM
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.