11-26-2012 07:30 PM - edited 11-26-2012 07:32 PM
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 :
12-04-2012 04:10 AM
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
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
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)
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
12-04-2012 05:49 AM
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)
12-04-2012 06:06 AM
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
12-04-2012 07:29 PM
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
12-05-2012 02:50 PM
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
12-05-2012 08:28 PM - edited 12-05-2012 08:42 PM
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?