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

我怕爱的太早我们不能终老 提交于 2019-12-09 06:35:09

问题


I've built an application which loads statistics from an external xml file on the web.

It works fine in the web browser. It also works fine when I package it with PhoneGap for Android. Works on BlackBerry Playbook as well.

However it doesn't work when I package it for BlackBerry. I have tried both WebWorks Command Line Tool and PhoneGap.


When I Package with WebWorks and Run on Simulator

The console on Web Inspector gives me the error

"Failed to load resource: the server responded with a status of 500 (Error requesting resources.)"

When I Package with Phonegap and Run on Simulator

When I package with PhoneGap instead of WebWorks I get the following errors poping up in alerts...

gap : ["Network Status", "getConnectionInfo","Network Status0",true]

gap: ["Device","getDeviceInfo","Device1",true]

gap_init:

gap_callbackServer:

gap_poll:

Live version of App (uncompiled)

ZIP file to run in WebWorks or Phonegap


similar unanswered question.


Youtube Video of Problem in BlackBerry Simulator


Things I've Tried

I've added to my config file.

<access subdomains="false" uri="*"/>

I've added a $.support.cors function suggested by phonegap.

$( document ).bind( "mobileinit", function() {
    // Make your jQuery Mobile framework configuration changes here!
    $.mobile.allowCrossDomainPages = true;
});

回答1:


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.




回答2:


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.




回答3:


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



来源:https://stackoverflow.com/questions/10799838/ajax-xml-not-working-on-blackberry-with-web-works-or-phonegap

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