I have a GWT app and I'm using RequestBuilder get GET some json from a php script I have running on a Fatcow.com server. It returns the json just fine in the browser and returns a 200 status in Charles web debug proxy, but in the GWT app it always says the response status is 0 and doesn't give me any json. When I test my code on a known working URL, it returns 200 and I get the json I expect. Also, I already have header('Content-Type: application/json; charset=utf-8'); in my php, which I know is a common error. Is there any reason this would not be working? Is it a php thing, or am I doing something wrong?
Asked
Active
Viewed 852 times
1 Answers
1
You're hitting the Same-Origin Policy.
CORS is supported in most recent browsers (exceptions: IE and Opera; will be coming in IE 10 and Opera 12 respectively).
Only viable alternatives are JSONP (using JsonpRequestBuilder
in GWT) or a "proxy" on the same server serving your GWT app.

Thomas Broyer
- 64,353
- 7
- 91
- 164
-
I'm running the GWT app from Eclipse and I'm accessing the php file online from my web server. http://acumeta.coryschulz.com/uibuilder/data/stocks.php So they're not from the same machine. – Cory Schulz Dec 03 '11 at 12:50
-
1Yes, that's what I said: you're hitting the Same-Origin Policy. If you intend to ultimately deploy on the same machine, then you can try that instead: [Using my own server in development mode instead of GWT's built-in Jetty instance](http://code.google.com/webtoolkit/doc/latest/DevGuideCompilingAndDebugging.html#How_do_I_use_my_own_server_in_development_mode_instead_of_GWT's) – Thomas Broyer Dec 03 '11 at 15:06
-
Yup, sorry, I misunderstood what SOP was. Is there a way that I can directly load a .json file such as www.coryschulz.com/data.json ? I've tried using jsonpRequestbuilder and it keeps on failing. What I'm trying to do is find a way to load some test data into a GWT app directly from a .json file. That wasn't working, so then I tried php instead. – Cory Schulz Dec 03 '11 at 15:24
-
Put your JSON file in your `war` directory. – Thomas Broyer Dec 03 '11 at 15:38
-
Yeah, I've tried that too. Still fails. You would think GWT would have some easy way to load test data in directly from a json file, but I haven't found any tutorials on it. – Cory Schulz Dec 03 '11 at 15:43
-
com.google.gwt.jsonp.client.TimeoutException: Timeout while calling http://127.0.0.1:8888/data/data.json – Cory Schulz Dec 03 '11 at 16:00
-
Okay, I was able to get the json to load from the war directory using RequestBuilder. I know I tried it before and it wasn't working, but now it seems fine. Thanks much for your help! – Cory Schulz Dec 03 '11 at 16:05