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

Posts: 39
Registered: ‎09-02-2011
My Device: Curve 9300
My Carrier: Tigo

Access data from the web

Hi all,


This seems a silly question, but nothing works for me!


I have a site from where I want to download some data (it's jason, don't think that matters though). For testing purposes, I configured a vhost so that http://mysite.localhost/getData.php points to where I want to extract the data from.


In the config.xml I whitelist that domain:

<access uri="http://mysite.localhost" subdomains="true">
        <feature id="blackberry.app" version="" required="true"/>
        <feature id="blackberry.invoke" version="" required="true"/>

 And then I try to access it like so:

var baseURL = 'http://mysite.localhost';
$.getJSON(baseURL + 'getData.php', function(data) {
    //do something with my data

 With the ripple emulator I get:

XMLHttpRequest cannot load http://mysite.localhost/getData.php. Origin http://localhost is not allowed by Access-Control-Allow-Origin.


When I deploy it anyways to the Blackberry 10 Dev Alpha Simulator, nothing happens. At least it doesn't show that not allowed screen.


Adding "--disable-web-security" to my Chrome shortcut also won't work. It says that command is not allowed since it affects stability and security.


What could be the issue? What can I do so it works in Ripple also and my life gets easier while I test my app?


Thank you..! Help is MUCH appreciated.

Posts: 39
Registered: ‎09-02-2011
My Device: Curve 9300
My Carrier: Tigo

Re: Access data from the web

Ok, I got it to work within Ripple.

I added a header to allow for cross domain on the server.


However, now the problem lies on the simulator, specifically the $.getJSON() function.


What is going on? How do I solve it?



New Developer
Posts: 35
Registered: ‎01-04-2012
My Device: BlackBerry Q10
My Carrier: o2

Re: Access data from the web

i have the same issue only on webworks for blackberry 10

my code works flawlessly on smartphone and playbook.

but no json data is being pulled through the blackberry 10 build. my guess is theres an API not been opened up yet. IDK Smiley Sad
Posts: 175
Registered: ‎12-18-2012
My Device: n/a
My Carrier: 2 Degrees NZ

Re: Access data from the web

[ Edited ]

what you need to do, is add &Callback=? to the URL

And makesure you are setting the right DataType and use $.ajax instead of $.getJSON


if using $.ajax - you can specify the data Type like JSON or JSONP


+Like this post, if you find it useful/helpful!