Blackberry WebWorks AJAX Problems

May 09, 2011
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


Related Entries

1 person found this page useful, what do you think?

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
@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.
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.
I'm trying exactly the same as you say but it still doesn't work. Do you have any working example to look at?
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
check this out guys http://developerfaq.wordpress.com/2011/07/26/ajax-on-blackberry-os-5-via-phonegap/

Post a Comment




  



Spell Checker by Foundeo

Recent Entries



foundeo


did you hack my cf?