Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Web and WebWorks Development

Reply
New Contributor
Posts: 4
Registered: ‎12-21-2010
My Device: Torch 9800
My Carrier: Claro Dominicana
Accepted Solution

AJAX Request just works with Wi-fi Blackberry Widget

I'm trying to do a Ajax Request to es RESTful WebService. When I run the simulator everything works fine, but when I install the blackberry widget on my Device (9800) the requests just works when I'm using the Wifi connection..

 

this is my config.xml file:

 

 

<?xml version="1.0" encoding="UTF-8"?>
<widget xmlns="http://www.w3.org/ns/widgets" xmlns:rim="http://www.blackberry.com/ns/widgets" version="0.2.0.0">
  <name>bbbb</name>
  <description>bbbb</description>
  <feature id="blackberry.ui.menu" required="true" version="1.0.0.0"/>
  <feature id="blackberry.invoke.BrowserArguments" required="true" version="1.0.0.0"/>
  <feature id="blackberry.invoke" required="true" version="1.0.0.0"/>
  <feature id="blackberry.app" required="true" version="1.0.0.0"/>
  <feature id="blackberry.app.event" required="true" version="1.0.0.0"/>
  <feature id="blackberry.identity" required="true" version="1.0.0.0"/>
  <feature id="blackberry.system" required="true" version="1.0.0.0"/>
  <feature id="blackberry.push" required="true" version="1.0.0.0"/>
  <feature id="blackberry.find" required="true" version="1.0.0.0"/>
  <access uri="http://mydomain/" subdomains="true">
    <feature id="blackberry.ui.menu" required="true" version="1.0.0.0"/>
    <feature id="blackberry.invoke.BrowserArguments" required="true" version="1.0.0.0"/>
    <feature id="blackberry.invoke" required="true" version="1.0.0.0"/>
    <feature id="blackberry.app" required="true" version="1.0.0.0"/>
    <feature id="blackberry.app.event" required="true" version="1.0.0.0"/>
    <feature id="blackberry.identity" required="true" version="1.0.0.0"/>
    <feature id="blackberry.system" required="true" version="1.0.0.0"/>
    <feature id="blackberry.push" required="true" version="1.0.0.0"/>
    <feature id="blackberry.find" required="true" version="1.0.0.0"/>
  </access>
  <access uri="*"/>
  <content src="index.html"/>
  <rim:connection timeout="25">
    <id>TCP_WIFI</id>
    <id>MDS</id>
    <id>BIS-B</id>
    <id>TCP_CELLULAR</id>
    <id>WAP2</id>
    <id>WAP</id>
  </rim:connection>
  <rim:navigation mode="focus"/>
  <rim:cache disableAllCache="true"/>
</widget>

 

Why this is happening?

 

Retired
Posts: 3,708
Registered: ‎10-16-2008
My Device: Z10
My Carrier: Rogers

Re: AJAX Request just works with Wi-fi Blackberry Widget

This is because you have set your transport order to the following:

 

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

 

You really only want to change your transport order if there is very specific reason to do so.  One tricky thing about transport is that it isn't the same as a physical connection.  You can best think of transports as VPN tunnels.

 

They don't have a correlation with a physical radio modem connection.  So even if MDS is first in your list, if you have a WiFi connection it will communicate through WiFi.

 

I would suggest removing the <rim:connection> element from your config file unless you have a very specific reason to make it go through the WiFi transport.  If your device isn't on WiFi and you have your transports selected like you currently do, it will wait for a connection timeout before it moves to MDS to try there.

 

Tim Neil
Director, Application Platform & Tools Product Management
Follow me on Twitter
Highlighted
New Contributor
Posts: 4
Registered: ‎12-21-2010
My Device: Torch 9800
My Carrier: Claro Dominicana

Re: AJAX Request just works with Wi-fi Blackberry Widget

I removed the <rim:connection> element but It doesn't work anyways.

 

This is an example how I'm doing the request:

 

 

function verify_last_version() {
	new ajax.request(
			"http://mydomain/restserver/",
			{
				relativeURL : false,
				method : 'get',
				header : [ "Authorization:"
						+ make_base_auth('user', 'password') ],
				json : true,

				onComplete : function(r) {
					if (r.json.last_version == $('#version').value) {
						alert("Congrats, you have the latest version.");
					} else {
						if (confirm("There is a New Version, do you want to Download the last Version?")) {
							var Bi = blackberry.invoke, args = new Bi.BrowserArguments(
									'http://mydomain/downloadapp');
							Bi.invoke(blackberry.invoke.APP_BROWSER, args);
						}
					}
				},
				onError : function(e, o) {
					alert(e.message);
				}
			});
}

 

e.message return: "Unknown error".

 

note: I'm using jsHack framework: http://jshack.net/

New Contributor
Posts: 4
Registered: ‎12-21-2010
My Device: Torch 9800
My Carrier: Claro Dominicana

Re: AJAX Request just works with Wi-fi Blackberry Widget

Finally! I found it! I don't why, but this just works on .com, .net o .org domains

 

I was doing request to a .mobi domain.

Contributor
Posts: 16
Registered: ‎05-17-2011
My Device: 9700
My Carrier: Bmobile

Re: AJAX Request just works with Wi-fi Blackberry Widget

I am actually experiencing this problem, my first webworks application.

 

It connects reliably over wifi, but less so over Direct TCP, and very unreliable over BIS using XMLHTTPRequest to an xml feed generated using ASP.NET 4.

 

my script is as follows:

 

 

var RSSRequestObject = false; // XMLHttpRequest Object

if (window.XMLHttpRequest) // try to create XMLHttpRequest
RSSRequestObject = new XMLHttpRequest();

if (window.ActiveXObject) // if ActiveXObject use the Microsoft.XMLHTTP
RSSRequestObject = new ActiveXObject("Microsoft.XMLHTTP");


/*
* onreadystatechange function
*/
function ReqChange() {

// If data received correctly
if (RSSRequestObject.readyState==4) {
// if data is valid
if (RSSRequestObject.responseText.indexOf('invalid') == -1)
{
// Parsing RSS
var node = RSSRequestObject.responseXML.documentElement;

// Get Channel information
var channel = node.getElementsByTagName('channel').item(0);

content ='';
// Browse items
var items = channel.getElementsByTagName('item');
for (var n=0; n < items.length; n++)
{
var itemTitle = items[n].getElementsByTagName('t').item(0).firstChild.data;
var itemLink = items[n].getElementsByTagName('lk').item(0).firstChild.data;
var itemTimes = items[n].getElementsByTagName(loc).item(0).firstChild.data;

content += '<div class="list-item"><h3>' + itemTitle+ '</h3><span class="times"><b>' +locname+' Show Times:</b><br/>' + itemTimes + '</span><a class="link" href="'+itemLink+'">Movie Info and Show Times</a></div>';
}

// Display the result
document.getElementById("ajaxreader").innerHTML = content;

// Tell the reader the everything is done
document.getElementById("status").innerHTML = "Done.";

}
else {
// Tell the reader that there was error requesting data
document.getElementById("status").innerHTML = '<div class="error">Error requesting data.<div>';
}

HideShow('status');
}
}

/*
* Main AJAX RSS reader request
*/
function RSSRequest() {

// change the status to requesting data
HideShow('status');
document.getElementById("status").innerHTML = '<h3 class="loading list-item"><img alt="" src="img/indicator.gif"/>&nbsp;Loading ...</h3>';

// Prepare the request
RSSRequestObject.open("GET", Backend , true);
RSSRequestObject.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
RSSRequestObject.setRequestHeader("Content-length", 100000);
RSSRequestObject.setRequestHeader("Connection", "close");
// Set the onreadystatechange function
RSSRequestObject.onreadystatechange = ReqChange;
// Send
RSSRequestObject.send(null);
}


function HideShow(id){
var el = GetObject(id);
if(el.style.display=="none")
el.style.display='';
else
el.style.display='none';
}

function GetObject(id){
var el = document.getElementById(id);
return(el);
}