AJAX XML does not work on BlackBerry with Web-Works or Phonegap

I created an application that downloads statistics from an external XML file on the Internet.

It works great in a web browser. It also works great when I pack it using PhoneGap for Android. Also works with the BlackBerry Playbook.

However, this will not work if I pack it for BlackBerry. I tried both the WebWorks command-line tool and PhoneGap.


When I pack with WebWorks and run on the simulator

Console in Web Inspector gives me an error

"Failed to load the resource: the server responded with a status of 500 (request with a request for errors).

When I pack with the phone and run on the simulator

When I pack using PhoneGap instead of WebWorks, I get the following errors appearing in warnings ...

gap : ["Network Status", "getConnectionInfo","Network Status0",true] gap: ["Device","getDeviceInfo","Device1",true] gap_init: gap_callbackServer: gap_poll: 

Live version of the application (not compiled)

ZIP file for working in WebWorks or Phonegap


similar unanswered question .


Youtube Video of Problem in BlackBerry Simulator


Things i tried

I have added to my configuration file.

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

I added the $ .support.cors feature offered by phone recording .

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

Is your simulator and WebWorks SDK updated?

I tested the Live PlayBook with 2.0.1.358 and in the 2.0.0.7971 simulator without the problems that I see.

I am packaged with 2.2.0.15 WebWorks for the PlayBook SDK, and the only thing I changed is the identifier in the config.xml file, which was not accepted in the dotted packet.


OK, now I see what the problem is.

This is pretty obscure, but Java Smartphones simulators are configured to work with another old simulator called MDS Simulator. This is not necessary for most things, but provides network connectivity similar to what the device sees in a corporate BES environment. The simulator believes that it has a so-called "MDS" connection all the time, even if the MDS Simulator does not work.

When using the WebWorks application, if you use the default config.xml file without the <rim:connection> (which is perfectly normal in most cases), it prioritizes MDS before TCP parameters. This is a problem because the sim thinks that it has an MDS connection when it does not actually occur, and that the connection attempt ultimately fails.

If you add the following bit of code to your config.xml file, this will reduce the priority of MDS and make it very simple.

 <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 element - you need to configure the simulator to use a simulated Wi-Fi network. Click on the top banner of the main screen (using the wireless indicator), then turn on Wi-Fi and click Wi-Fi Network in the settings and status. Then click on the default WLAN and follow the steps to link it.

+8
source

I assume this is due to configuration 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 automatically expose the javascript APIs that you request in your configuration file (i.e. window.blackberry.* ), Without having to make requests, for example, for http://localhost:8472/blackberry/extensions/get .

Since you just make ajax calls, I would drop all of this and focus on debugging your ajax code.

PS: Phonegap runs on top of WebWorks, so abstracting things out will most likely not solve your problem.

+1
source

It seems like the problem of sharing resources between different sources. You probably need to use CORS

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

In your javascript, use this to request 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/mp/1736733#M24128

0
source

Source: https://habr.com/ru/post/1414884/


All Articles