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: 270
Registered: ‎12-13-2010
My Device: PlayBook 16GB, BB10 Dev Alpha
My Carrier: o2 (de)

Issue opening local files via AJAX

I stumbled upon another problem. Perhaps anyone can help me out or confirm this as a bug.

Since no debugger or JavaScript-console is available in the emulator, I feel a bit like searching for a needle in the haystack (using only alert's)...

 

What I'm trying to do is reading local json files. I did it in different ways, but since none worked I post the shortest and easiest (JQuery) excerp here:

 

 

$(document).ready(function() {
	$(document).ajaxError(function(e, xhr, settings, exception) {
		alert('error in: ' + settings.url + ' \n'+'error:\n' + xhr.responseText );
	});
	xyz();
});

// ...

function xyz() {
	$.getJSON('d/countries.json', function(data) {
		//THIS IS NEVER CALLED!
		alert("Got JSON...");
	});
}

This code works as expected in Chrome (called with google-chrome --args --disable-web-security --allow-file-access-from-files) and Firefox.

 

 

The "funny" thing about it is that I get my error alert with xhr.responseText being the content of my file.

 

Ideas anyone?

- - -
My approved apps @ App World
Developer
Posts: 270
Registered: ‎12-13-2010
My Device: PlayBook 16GB, BB10 Dev Alpha
My Carrier: o2 (de)

Re: Issue opening local files via AJAX

[ Edited ]

No ideas anyone? I'm really stuck at the moment w/o local file access...

- - -
My approved apps @ App World
Developer
Posts: 382
Registered: ‎05-19-2008
My Device: BlackBerry Torch
My Carrier: AT&T

Re: Issue opening local files via AJAX


biggerCC wrote:

 

	$.getJSON('d/countries.json', function(data) {

The file path looks imcomplete. Is that supposed to be a local file path? D:\countries.json perhaps?

 

all file references in BB should use a URL style. Also there are a couple of 'home' directories that are mapped to the local filesystem. So the path should be something like  (and I'm saying this from memory, so it might not be 100% correct) 'file:///SDCard/BlackBerry/Myapp/countries.json' for instance.

 

the file:// is the URL style formatting for a local file.

the /SDCard is one of two virtual directories that, in this case, map to the SD Card.

 

I <THINK> that resources in the project can be referenced using the 'local://' style URL. Do some digging and I hope it helps.

 

Bill

Bill
-------------------------------------------
Check out my book on BlackBerry Development for Java.
And my other really really old book
My Apps: FlashKids
Developer
Posts: 270
Registered: ‎12-13-2010
My Device: PlayBook 16GB, BB10 Dev Alpha
My Carrier: o2 (de)

Re: Issue opening local files via AJAX

 

Hi Bill,

billfoust wrote:

The file path looks imcomplete. Is that supposed to be a local file path? D:\countries.json perhaps?

 


 

I always use relative file pathes. As this works in my browser, this shouldn't be the issue.

 


billfoust wrote:

 

the file:// is the URL style formatting for a local file.

the /SDCard is one of two virtual directories that, in this case, map to the SD Card.

 


 

"file://" is in fact used for accessing local files. But only for those that come not bundled in the bar file...

 

Problem still unresolved... :/

- - -
My approved apps @ App World
Developer
Posts: 189
Registered: ‎08-13-2008
My Device: Not Specified

Re: Issue opening local files via AJAX

Hi

 

Could this be related to cross domain ajax call??

 

cross domain json

 

Just a thought.

 

cheers

 

Andrew

Highlighted
Developer
Posts: 270
Registered: ‎12-13-2010
My Device: PlayBook 16GB, BB10 Dev Alpha
My Carrier: o2 (de)

Re: Issue opening local files via AJAX

Hi Andrew,

 

thanks for that link. I have already been searching through all JSON related WebWorks forum entries... Unluckily all mention server-based communication, this is where the cross-domain-security-thing comes in (which can be solved by allowing access in the config.xml).

I'd expect not to run into this error, since both files are on the same "server"/device (= the local file storage within the .bar).

 

What I've done now, was to redirect all AJAX calls to my webserver, where I host the files until any solution comes up. It works, but of course isn't a very reasonable workaround.

 

I will open a case in the bugtracker on this...

- - -
My approved apps @ App World