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
Developer
Posts: 676
Registered: ‎05-06-2012
My Device: Dev Alpha & PlayBook
My Carrier: wifi
Accepted Solution

AJAX from external website not working?

I've built an application which loads statistics from an external xml file on the web. It works fine in a browser but after packagaing it with webworks and running it in the simulator the AJAX never loads.

 

I've added 

 

<access subdomains="false" uri="http://www.mysite.com"/>

 

to my config file but that didn't help. Are there any other permissions or things I need to set to get this working?

_________________________________________________________
co-founder of Diaree | BB Dev for PictureThis
Developer
Posts: 62
Registered: ‎04-29-2010
My Device: N/A

Re: AJAX from external website not working?

Try using this:

 

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

 

If that doesn't work then we'll know it's not a config issue.

Developer
Posts: 676
Registered: ‎05-06-2012
My Device: Dev Alpha & PlayBook
My Carrier: wifi

Re: AJAX from external website not working?

That doesn't help but works fine in browser and also works fine when packaged from phonegap to Android. Will have to try using phonegap instead of webworks and see if it works then.

_________________________________________________________
co-founder of Diaree | BB Dev for PictureThis
Highlighted
Developer
Posts: 676
Registered: ‎05-06-2012
My Device: Dev Alpha & PlayBook
My Carrier: wifi

Re: AJAX from external website not working?

With phonegap I get the following errors poping up

 

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

 

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

 

gap_init:

 

gap_callbackServer:

 

gap_poll:

_________________________________________________________
co-founder of Diaree | BB Dev for PictureThis
Contributor
Posts: 41
Registered: ‎04-27-2010
My Device: Z10
My Carrier: VIettel

Re: AJAX from external website not working?

[ Edited ]

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();
}

 

Hope this helps.

 

---
More applications/games here: http://appworld.blackberry.com/webstore/vendor/14299/
louis.keeper@gmail.com
haitt@viethop.net
http://blackberryvietnam.net
http://viethop.com
Developer
Posts: 676
Registered: ‎05-06-2012
My Device: Dev Alpha & PlayBook
My Carrier: wifi

Re: AJAX from external website not working?

Tim Windsor helped me out with this one. The solution was to add the following to the webworks config.xml file.

 

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

_________________________________________________________
co-founder of Diaree | BB Dev for PictureThis
New Member
Posts: 1
Registered: ‎08-21-2012
My Device: 9300
My Carrier: Blackberry

Re: AJAX from external website not working?

Hi All,

 

Working with phonegap, trying to capture an image using the device camera and upload the image to the server.

 

This works with me android phone.  When tried in Blackberry 9300 , 9360 it throws Internal server server :500

 

Can someone help me on how to resolve it.

 

thanks and regards,

Hema