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: 23
Registered: ‎06-07-2012
My Device: 9810
My Carrier: MTC

Get json from another domain

Hi All!

 

I have nxt problem:

in webworks app I need to get JSON data from another server. But - domain policy.

How can I do that?

 

Thanks!

Retired
Posts: 1,382
Registered: ‎07-02-2009
My Device: BlackBerry Bold 9900
My Carrier: Bell

Re: Get json from another domain

You must whitelist the URL of the external domain in the config.xml document.  WebWorks allows cross-domain access (unlike the browser) as long as the URL is trusted.

 

https://developer.blackberry.com/html5/documentation/access_element_834677_11.html

Follow me on Twitter: @n_adam_stanley
-------------------------------------------------------------------------------------------------------------------------
Your app doesn't work? Use BlackBerry remote web inspector to find out why.
Developer
Posts: 270
Registered: ‎12-13-2010
My Device: PlayBook 16GB, BB10 Dev Alpha
My Carrier: o2 (de)

Re: Get json from another domain

If you can control the serverside too (e.g. it's your own backend), I'd also take this information about cross-site HTTP requests into consideration.

 

Altough you won't need it if you use your AJAX requests only in wrapped WebWorks apps, but it helps when you test stuff on your regular PC or smartphone browser.

 

In many cases you just add one line to your HTTP headers. In PHP this might look like this:

<?php
    header('Access-Control-Allow-Origin: *');

[... your code ...]

 

- - -
My approved apps @ App World