AJAX XML not working on BlackBerry with Web-Works or Phonegap

。_饼干妹妹 提交于 2019-12-03 09:12:21

Is your simulator and WebWorks SDK up to date?

I've tested on a live PlayBook with 2.0.1.358 and in the simulator for 2.0.0.7971 with no problems that I can see.

I packaged with the 2.2.0.15 WebWorks for PlayBook SDK, and the only thing I changed was the id in config.xml, which wasn't accepted in the packager with the dots.


Okay, now I see what the problem is.

It's pretty obscure, but the Java Smartphones sims are setup to work with another old simulator tool called the MDS Simulator. It's not really necessary for most things, but provides networking similar to what a device sees in a Corporate BES environment. The simulator believes it has what is called an "MDS" connection all the time even if the MDS Simulator isn't running.

With a WebWorks app, if you use a default config.xml file with no <rim:connection> tag (which is totally fine for most cases), it prioritizes MDS before the TCP options. This is a problem because the sim thinks it has an MDS connection when it actually doesn't and that connection attempt eventually fails.

If you add the following bit of code to your config.xml, it will reduce the priority of MDS and should make it work just fine.

<rim:connection timeout="60000">
    <id>BIS-B</id>
    <id>TCP_WIFI</id>
    <id>TCP_CELLULAR</id>
    <id>MDS</id>
    <id>WAP2</id>
    <id>WAP</id>
</rim:connection>

And one last Critical item - you need to set up the simulator to use the simulated wifi network. Click on the top banner of the homescreen (by the wireless indicator), then turn on Wifi, and click on Wi-Fi Network in Options and Status. Then Click on Default WLAN Network and go through the steps to associate it.

I assume this has to do with the setup calls near the end of your webworks.js. I'm not sure where you got this library, but it seems a little old.

WebWorks should expose the javascript APIs that you request in your config file automatically (ie: window.blackberry.*) without the need to make requests like you have to http://localhost:8472/blackberry/extensions/get.

Since you're just making ajax calls, I'd drop all of that and focus on debugging your ajax code.

PS: Phonegap works on top of WebWorks, so abstracting things further won't likely solve your problem.

It looks like cross-origin resource sharing issue. You probably have to use CORS

Enable it on server-side: http://enable-cors.org/

In your javascript, use this to request for the remote content:

// Create the XHR object.
function createCORSRequest(method, url) {
var xhr = new XMLHttpRequest();
if ("withCredentials" in xhr) {
    // XHR for Chrome/Safari/Firefox.
    xhr.open(method, url, true);
} else if (typeof XDomainRequest != "undefined") {
    // XDomainRequest for IE.
    xhr = new XDomainRequest();
    xhr.open(method, url);
} else {
    // CORS not supported.
    xhr = null;
}
return xhr;
}

// Make the actual CORS request.
function makeCorsRequest() {

var url = "http://www.example.com/";

var xhr = createCORSRequest('GET', url);

if (!xhr) {
    alert('CORS not supported');
    return;
}

// Response handlers.
xhr.onload = function() {
    var text = xhr.responseText;
    // Do something with returned text data
};

xhr.onerror = function() {
    alert('Woops, there was an error making the request.');
};

xhr.send();
}

from: http://supportforums.blackberry.com/t5/Web-and-WebWorks-Development/AJAX-from-external-website-not-working/m-p/1736733#M24128

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!