Pete Freitag Pete Freitag

Blackberry WebWorks AJAX Problems

Updated on December 07, 2023
By Pete Freitag
web

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 included json2.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 mobile webworks troubleshooting ajax phonegap jquerymobile

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:

Discuss / Follow me on Twitter ↯

Comments

halo pete,

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
by phonegap-newbie on 07/14/2011 at 9:04:48 PM UTC
@phonegap-newbie you can just use the standard XMLHttpRequest object or a framework like jQuery to do your AJAX request. The navigator.network.XHR as mentioned in my post is not for the latest phonegap, it is for the older java version.
by Pete Freitag on 07/14/2011 at 9:09:56 PM UTC
yeah,

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.
by phonegap-newbie on 07/15/2011 at 9:23:41 AM UTC
I'm trying exactly the same as you say but it still doesn't work. Do you have any working example to look at?
by Gil Forcada on 07/18/2011 at 1:57:43 PM UTC
I have the same problem.
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
by Alex on 07/24/2011 at 4:33:02 PM UTC