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
Contributor
Posts: 19
Registered: ‎06-14-2011
My Device: 9300
My Carrier: Comcel
Accepted Solution

JSONP not working in webworks compiled app

[ Edited ]

Hello everyone, this is my first post (desperate post!)

 

I have been working on this app for about a month, it uses the following scripts/frameworks/SDK:

 

- jquery 1.6.1

- jquery mobile 1.0a4.1

- BlackBerry WebWorks SDK2.0.0.201103231828-18

- BlackBerry WebWorks Plug-in2.5.1.201010291444-2 (eclipse)

 

it uses JSONP to avoid ajax cross-domain restrictions (app and data in different servers), and is working fine with chrome and BB browser (OS v6.0.0.576) on my phone, no restrictions at all. But when I compile and install the app as a native Webworks app on the phone, every request (same network, same external IP, etc.) I get nothing, status = 0 statusText = timeout on every request. My config.xml is this:

 

<?xml version="1.0" encoding="UTF-8"?>
<widget xmlns="http://www.w3.org/ns/widgets" xmlns:rim="http://www.blackberry.com/ns/widgets" version="1.0.0.1">
  <name>My app</name>
  <author rim:copyright="xxx" email="xxx">xxx</author>
  <access subdomains="true" uri="*"/>
  <icon rim:hover="false" src="img/bricks.png"/>
  <icon rim:hover="true" src="img/brickshover.png"/>
  <content src="index.html"/>
  <rim:loadingScreen foregroundImage="img/splash.png" onFirstLaunch="true">
    <rim:transitionEffect type="zoomIn"/>
  </rim:loadingScreen>
  <rim:cache disableAllCache="true"/>
</widget>

 

 

just set domain access to "*", and even with that nothing happens Smiley Sad

 

As in documentation, if remote domains/IPs change dynamically then is recommended using "*" to avoid restrictions, in this case it seems not to be working as expected.

 

This is how i´m making calls over JSONP:

 

(with jquery)

 

function queryService(srvUrl, callbackFunc){
	
	if(globalVars['ssl'] == "1"){
		srvUrl = "https://"+srvUrl;
	}else{
		srvUrl = "http://"+srvUrl;
	}
	
	
	
	$.mobile.pageLoading(); 
	

	$.ajax({
		type: "GET",
		url: srvUrl,
		crossDomain: true,
		cache: false,
		dataType: "jsonp",
		jsonp : "callback", //Server only supports JSONP param name "callback"
		jsonpCallback: callbackFunc,
		timeout: 10000,
		error: (function(xhr, ajaxOptions, thrownError){
			
			$.mobile.pageLoading(true);
			
			alert("Error:"+xhr.status+"-"+xhr.statusText+"-"+thrownError);
			
		}),
		success: (function(){
			$.mobile.pageLoading(true);
		})
	});
}

Now just make every call like this:

 

queryService("192.168.1.12:8051/info/AABBCCDD", "mycallbackfunc");

 

Now the funny part is that the app is fully functional as a webpage on mobile (BB browser os6) and desktop, but as a native app for blackberry it doesn't retrieve information.

 

Even changed to another JSONP library (Lightweight JSONP fetcher by Erik Karlsson) just to discard a bug on jquery but got the same result.

 

Any suggestions? your help will be much appreciated, thanks!

 

EDIT: I forgot, on BB 9800 emulator (OS v6.0.0.227) it works just as expected (compiled app). 

Highlighted
Contributor
Posts: 19
Registered: ‎06-14-2011
My Device: 9300
My Carrier: Comcel

Re: JSONP not working in webworks compiled app

Ok, found it! Smiley Happy, domain access "*" only works for public IPs, so no intranet love for my app, but that's ok