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
New Contributor
dheo
Posts: 4
Registered: ‎12-15-2012
My Device: 9700
Accepted Solution

XMLHttpRequest cross-server

I tried to get data from other server using xmlhttprequest.

 

When code run in simulator it's work perfectly, but when I try to run on Blackberry 10 Dev Alpha B it's always get empty response. (status = 0)

 

 

Please use plain text.
Developer
MirkoAgrati
Posts: 26
Registered: ‎10-30-2012
My Device: Z10 Limited Edition / PlayBook / BB10 Dev A-B-C / Bold 9700

Re: XMLHttpRequest cross-server

[ Edited ]

Hi :smileyhappy:

Also I have a problem similar to your.

In ripple all works fine, but when I run my app on dev alpha all the XMLHttpRequest are not allowed.
see the attached image.

XMLHttpRequest are forbidden either in HTTP either in HTTPS, but if I invoke the browser from my app in dev alpha it opens the urls :smileysad:

in attachment there is also my config.xml (i've tried different solutions, but I didn't solve the problem).

Any idea or workaround?

 

tnx.

MA

 

Please use plain text.
Developer
peardox
Posts: 1,229
Registered: ‎03-20-2011
My Device: Playbook, Z10 LE, Dev Alpha B, 2x Dev Alpha C

Re: XMLHttpRequest cross-server

I've got an A

 

Can you update your device to 1675 - everything appears to work on that version

 

I had all sorts of probs using 1103 but 1675 and gold SDK work perfectly on everything I throw at it




Click the like button if you find my posts useful!
Please use plain text.
Developer
MirkoAgrati
Posts: 26
Registered: ‎10-30-2012
My Device: Z10 Limited Edition / PlayBook / BB10 Dev A-B-C / Bold 9700

Re: XMLHttpRequest cross-server

Hi peardox :smileyhappy:

 

I've already installed the last OS dev Alpha, the SDK GOLD and bbui.js 0.95 .

 

This 's the best environment, but every ajax request is not allowed.

 

Either with unsigned bar either with a signed one!

 

I really can't understand.

 

Packagin and signing steps  went OK, no warnning and no error.

 

 

Please use plain text.
Developer
peardox
Posts: 1,229
Registered: ‎03-20-2011
My Device: Playbook, Z10 LE, Dev Alpha B, 2x Dev Alpha C

Re: XMLHttpRequest cross-server

OK

 

I just ran up a quick little stupid app for demo purposes

 

I use JQuery as it's reliable

 

This very stupid app just echos whatever you send it

 

You can find the source here - change line 28 of index.html from Hello World to whatever you like and you get it back

 

I've kept everything in as few files as possible so the JS is in the header

 

The ZIP includes the script on the server side

 

The text comes out really tiny (I just wanted to get it working for you guys)

 

The doc, when loaded, calls http://safepear.com/junk.php when throws what it gets back into the xdom div

 

The important thing is setting the msg variable (Hello World) - change this to whatever you like

 

The script on the server takes msg and simply sends it back (boring)

 

Your variant of junk.php needs to take your proper input - do what you like with it - then return something JS can use

 

JSON is best if you're on PHP 5,3 or better as it can crunch an array into an object - takes a bit of experimentation though

 

I use exactly this process professionally and it never fails

 

The code in the example is a bit ropey as I wanted to keep it as short as possible

 

I use error checks and handshakes on real world stuff

 

The app will run out of the box

 

Simply kill junk.php, modify config.xml and change line 28 of index.html

 

Oh - again - stick a big font in index as well for #xdom

 

Done 4 builds to get it this far - not doing another just to make it pretty




Click the like button if you find my posts useful!
Please use plain text.
New Contributor
dheo
Posts: 4
Registered: ‎12-15-2012
My Device: 9700

Re: XMLHttpRequest cross-server

After upgrading to 1675, it's working both on simulator and on device.

thanks.
Please use plain text.
New Contributor
dheo
Posts: 4
Registered: ‎12-15-2012
My Device: 9700

It's working after upgarde to 1675   thanks peardox

It's working after upgarde to 1675

 

thanks peardox

Please use plain text.
Developer
MirkoAgrati
Posts: 26
Registered: ‎10-30-2012
My Device: Z10 Limited Edition / PlayBook / BB10 Dev A-B-C / Bold 9700

Re: XMLHttpRequest cross-server

Hi peardox :smileyhappy:

 

I've tried your example app and it works fine.

 

But when I try to make HTTPS requests I get always the same error.

 

I'm sure that problems are in the config.xml file but I can't really understand how to configure the <access> element.

 

Have you one config.xml example file in which there're HTTPS access element?

 

Tnx.

 

Bye

MA 

Please use plain text.
New Contributor
dheo
Posts: 4
Registered: ‎12-15-2012
My Device: 9700

Re: XMLHttpRequest cross-server

In my code, I put this code in config.xml

 

<access uri="https://hattrick.org" subdomains="true" />
<access uri="http://hattrick.org" subdomains="true" />

 

(don't put sub-domain part on uri)

 

this is working for me.

Please use plain text.
Developer
MirkoAgrati
Posts: 26
Registered: ‎10-30-2012
My Device: Z10 Limited Edition / PlayBook / BB10 Dev A-B-C / Bold 9700

Re: XMLHttpRequest cross-server

FOUND THE SOLUTION :smileyhappy:

 

The problem was that in the used URL there was a email address that had not been encoded.

 

the char '@' is forbidden. After using the javascript encodeURIComponent function the ajax requests work fine.

 

 

Tnx for the support :smileyhappy:

 

MA

Please use plain text.