Blackberry WebWorks AJAX Problems
By Pete Freitag
I recently spent some time debugging AJAX connections for a application I built for a client using Blackberry WebWorks (via PhoneGap) and jQuery Mobile. The app was already working great on iOS and Android, however my AJAX (XMLHTTPRequest's) were not working on Blackberry.
I quickly found that the config.xml
descriptor required whitelisting of the domain(s) you are connecting to. This particular app would be connecting to a number of unknown domains, so I had to use a wildcard like this:
<access uri="*" />
But I was still having a problem accessing my services, it would always report a 500 status code Internal Server Error.
Searching around for this issue I found some references to a Phonegap workaround for AJAX: navigator.network.XHR
- this however is not part of phonegap for WebWorks, it is part of the older phonegap which used the Blackberry java SDK rather than WebWorks. Unless you need to support old Blackberry phones (which uses a really barebones browser, not webkit) you probably want to be using the WebWorks version of PhoneGap.
It turns out my problem was very simple. Every time the simulator was fired up Networking was turned off, so you have to explicitly turn on the Wifi each time!
Here are a few tips on working with Blackberry WebWorks and PhoneGap:
- When working with PhoneGap make sure you are using the blackberry version of
phonegap.js
and also make sure that you have includedjson2.js
(required in v0.9.4) - If you run into JVM Error 545, run the clean.bat located in the simulator directory.
- Add this JS to make the page take up the full screen height:
document.body.style.height = screen.height;
- Keep in mind that if you want to support Blackberry 5, it's browser is not nearly as good as Blackberry 6, HTML5 features like
localStorage
may not work. - Checkout the Blackberry WebWorks Forum's Tips, Quirks & Solutions Thread
Blackberry WebWorks AJAX Problems was first published on May 09, 2011.
If you like reading about blackberry, mobile, webworks, troubleshooting, ajax, phonegap, or jquerymobile then you might also like:
- Building iPhone Android Apps with jQuery Mobile and PhoneGap Slides
- Building a Web Browser App for Blackberry Playbook Simulator
- Getting Started with Blackberry Playbook App Development
- Getting Started with jQuery Mobile
Discuss / Follow me on Twitter ↯
Tweet Follow @pfreitagComments
now i use jQuery and jsonp plugin to retrieve json from the server to my PhoneGap app. And i tested it in android 2.3 and blackberry os 6 simulator, and it worked well, but when i tested it in blackberry os 5, the ajax request to retrieve json seems an error occurred. I've visit many other site, but i do not found any clue about this problem.
Thx for your response Pete.
I have tried raw-xmlhttprequest in os 5, and it seems to work. However, this does NOT work in os 6...
var req = new XMLHttpRequest();
req.open('GET', URL, true);
req.onreadystatechange = function() {
if(this.readyState == 4 && this.status == 200) {
alert(this.responseText);
};
req.send(null);
Any of you could get jquery-ajax working in BB os 5?
Thx
how can you get navigator.network.XHR working ?
because, i use the latest PhoneGap 0.9.6, but it's not working in BlackBerry OS 5 Simulator. I recognize that in phonegap.js itself, those method doesn't exist.
So, can you give tips to fix this problem?
thx