SOLVED
I assume this is due to the Same Origin Policy.

When I put the compiled GWT code on the production server, which is
the same URL in my question below, it works fine.

I had been testing this code locally (on the "development server"),
but making a URL request to the remote server (the "production
server").

I suppose I would have to truly mirror development and production
environments to test locally on the "development server" to not see
this error, and still use GWT debugging, rather than only testing
compiled code.


On Mon, Sep 10, 2012 at 2:13 PM, Dee Ayy <dee....@gmail.com> wrote:
> I'm following 
> https://developers.google.com/web-toolkit/doc/latest/DevGuideServerCommunication#DevGuideHttpRequests
>
> I have
>                                 String url = "http://.../index.php";;
>                                 RequestBuilder builder = new 
> RequestBuilder(RequestBuilder.GET,
> URL.encode(url));
>
>                                 try {
>                                         Request request = 
> builder.sendRequest(null, new RequestCallback() {
>                                                 public void onError(Request 
> request, Throwable exception) {
>                                                         // Couldn't connect 
> to server (could be timeout, SOP violation, etc.)
>                                                 }
>
>                                                 @Override
>                                                 public void 
> onResponseReceived(Request request, Response response) {
>                                                         
> Window.alert("getStatusCode:" + response.getStatusCode());
>                                                         if (200 == 
> response.getStatusCode()) {
>                                                                 // Process 
> the response in
>                                                                 // 
> response.getText()
>                                                                 
> Window.alert("RESPONSE:" + response.getText());
>                                                         } else {
>                                                                 // Handle the 
> error. Can get the status
>                                                                 // text from 
> response.getStatusText()
>                                                                 
> Window.alert("OTHER STATUS:" + response.getStatusText());
>                                                         }
>                                                 }
>                                         });
>                                 } catch (RequestException e) {
>                                         // Couldn't connect to server
>                                 }
>
> I get an alert box from the above code "getStatusCode:0" although my
> Apache2 access logs has code 200 when this code is hit.
>
> (And then "OTHER STATUS:" with empty status text).
>
> A comment in stackoverflow says, "We've found a status code of "0"
> usually means the user navigated to a different page before the AJAX
> call completed."
>
> Going directly to the URL in a browser returns a test JSON string
> [{"symbol":"ABC","price":40.485578668179,"change":-0.53944918844604},
>  {"symbol":"DEF","price":1.3606576154209,"change":0.0051755221198266}]
>
> Please advise.

-- 
You received this message because you are subscribed to the Google Groups 
"Google Web Toolkit" group.
To post to this group, send email to google-web-toolkit@googlegroups.com.
To unsubscribe from this group, send email to 
google-web-toolkit+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-web-toolkit?hl=en.

Reply via email to