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
septard
Posts: 29
Registered: ‎11-22-2012
My Device: Blackberry Bold 9700

Ripple error when requesting an xmlhttprequest

[ Edited ]

guys i'm building webworks application which needs an ajax request to the web server

the application works fine when the web server is still on the same host (localhost:280 / AppServ), but when i already hosted the web server on the web host, i got this error :

XMLHttpRequest cannot load http://api.tinyhippos.com/xhr_proxy?tinyhippos_apikey=ABC&tinyhippos_rurl=http%3A//www.myloc.site90.... Origin http://localhost:280 is not allowed by Access-Control-Allow-Origin.
XMLHttpRequest cannot load http://api.tinyhippos.com/xhr_proxy?tinyhippos_apikey=ABC&tinyhippos_rurl=http%3A//www.myloc.site90.... Origin http://localhost:280 is not allowed by Access-Control-Allow-Origin.

can any one help me???

note : i already add  <access subdomains="true" uri="*"/> in the config.xml and off course i have change the xmlhttprequest address (not pointing to localhost:280 again, but to the hosted webserver)


Contributor
septard
Posts: 29
Registered: ‎11-22-2012
My Device: Blackberry Bold 9700

Re: Ripple error when requesting an xmlhttprequest

please help me :smileysad:

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

Re: Ripple error when requesting an xmlhttprequest

I'll write a little example script today and fully test it then give you the code




Click the like button if you find my posts useful!
Developer
peardox
Posts: 1,229
Registered: ‎03-20-2011
My Device: Playbook, Z10 LE, Dev Alpha B, 2x Dev Alpha C

Re: Ripple error when requesting an xmlhttprequest

OK

 

Local testing needs XAMPP installing so you've got a server to play with

 

This is ripped from a WIP piece and stripped to quickly show you what to do

 

This version is rather large as it's a test piece using BootStrap (not required) and JQuery (required)

 

Grab http://safepear.com/testxdom.zip then unzip into the htdocs directory of XAMPP

 

Open http://localhost/testxdom/

 

It's a dumb little thing that just opens a modal where you type in some text and get an MD5 back but illustrates how everything works

 

In script/xdom.js there are two important bits

---------------

1) sendQuery()

 

This extracts the data from the form then sends it to the URL you supply

 

Note the url var in this routine - it can go anywhere in the world, just change the URL and it'll go to a server for example

 

I return consistant data from my server side scripts much in the way that DLLs do so I can check if everything went as expected (which is where res.result comes in)

 

2) jsonpost()

 

This just sends the query to the server and parses the result. I stick it in a function by itself as I constantly do JSON messaging

-------------------

sender.php is a stupid little script which could be done in JS just as easily - it's just to show how you send things back properly - I just take whatever you typed in and MD5 it then send it back

 

I actually use something a bit like this (cryptographically secure though) with a SQL backend on a real project to identify a handshake message

 

This runs perfectly in all browsers, Ripple and almost anything else.

 

There's not a lot of limitations - I've used exectly this sort of thing to return highly complex tree structures for client-side visualisation

 




Click the like button if you find my posts useful!
Contributor
septard
Posts: 29
Registered: ‎11-22-2012
My Device: Blackberry Bold 9700

Re: Ripple error when requesting an xmlhttprequest

thanks sir ^^

 

you're using jquery Ajax in that code..

 

is it not okay to use a native ajax request???? *just to confirm.

 

cuz it'll be a disaster if i have to change all of my code (ajax request code)

 

 

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

Re: Ripple error when requesting an xmlhttprequest

You could try modifying it to use native but I find that very problematic

 

The JQuery library works on just about everything going which makes porting to other devices easy

 

You've seen my sample code and presumably tested it - I can guarantee that the sample is portable

 

You could use native code but it can be a mistake (a huge number of people make sure it works everywhere)

 

There is no requirement to use JQuery but I suggest you do, The code changes should be fairly simple

 

JQuery merely wraps a call in a standard way

 

I'd make a little test version using native replacing my JQuery Ajax with your own to see it it works

 

This may solve your problem as it's the request headers and returned object that matter and cause the issues (Android completely screws up without the XDOM)

 

Chrome is also an issue as it don't like XDOM from local - hence XAMPP

 

Have you tried moving your own project into htdocs? Its more than likely to work that way

 

XDOM is the most common issue in the situation you describe

 

Click the like thing :smileyhappy:




Click the like button if you find my posts useful!
Developer
peardox
Posts: 1,229
Registered: ‎03-20-2011
My Device: Playbook, Z10 LE, Dev Alpha B, 2x Dev Alpha C

Re: Ripple error when requesting an xmlhttprequest

I've just done a system rebuild (Windows 8 kills BB Dev tools)

 

I noticed something when installing Ripple (I never use it but want the full kil)

 

In Chrome go to chrome://chrome/extensions/

 

There's an option that lets you open local URLs - this will make a huge difference when trying something out quickly on the local file system

 

If doing anything that's gonna end up on a server then XAMPP is the simplest and most robust way to do things (I'd recommend that method)

 

It's handy to know that you can hack up something with local access though

 

 




Click the like button if you find my posts useful!
Developer
The_Anomaly
Posts: 322
Registered: ‎08-06-2012
My Device: Dev Alpha / Playbook / Curve 9300

Re: Ripple error when requesting an xmlhttprequest

The problem is that ripple is a Chrome extension and Chrome has a security "feature" which does not allow Cross Origin Resource Sharing - ie: the CORS issue (Google this there's tons of info) .  

 

You need to setup your chrome shortcut or create a new one with the "--disable-web-security" command line.

 

CORS scenarios include:

1.  Running your app from file:// and accessing http:// url for the ajax.  Same machine BUT 2 different domains.

2.  Running your app using the ripple HTTP localhost BUT accessing an online HTTP url.

 

There are more but I think you get the idea.  The reason XAMPP works is because its configured to allow "Access-Control-Allow-Origin"  Generally servers aren't

If it helped you, click like. :smileyhappy:
Contributor
septard
Posts: 29
Registered: ‎11-22-2012
My Device: Blackberry Bold 9700

Re: Ripple error when requesting an xmlhttprequest

[ Edited ]

thanks sir.

 

okay, it's okay my app didn't work well in ripple, but this error (requesting httprequest) caused my app didn't work well on my device too. I only changed the XHR destination to the hosted server, and added <access url="*"/>. I thought, the error was still about the XHR. any solution guys?