]> source.dussan.org Git - gwtquery.git/commitdiff
Ajax should handle statusCode == 0 as an error
authorManuel Carrasco Moñino <manuel.carrasco.m@gmail.com>
Mon, 5 Nov 2012 10:48:12 +0000 (11:48 +0100)
committerManuel Carrasco Moñino <manuel.carrasco.m@gmail.com>
Mon, 5 Nov 2012 10:48:12 +0000 (11:48 +0100)
gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/ajax/Ajax.java

index 64e713db0b24bf4e1a248d3e1c97502e9950b5b2..832fda8b6baffc7ee50577c47e6d69c2bef0e29e 100644 (file)
@@ -117,7 +117,7 @@ public class Ajax extends GQuery {
     
     Method httpMethod = resolveHttpMethod(settings);
     String data = resolveData(settings, httpMethod);
-    String url = resolveUrl(settings, httpMethod, data);
+    final String url = resolveUrl(settings, httpMethod, data);
     final String dataType = settings.getDataType();
     
     if ("jsonp".equalsIgnoreCase(dataType)) {
@@ -135,7 +135,12 @@ public class Ajax extends GQuery {
       }
 
       public void onResponseReceived(Request request, Response response) {
-        if (response.getStatusCode() >= 400) {
+        int statusCode = response.getStatusCode();
+        if (statusCode <= 0 || statusCode >= 400) {
+          if (statusCode == 0) {
+            // Just warn the developer about the status code
+            GWT.log("GQuery.ajax error, the response.statusCode is 0, this usually happens when you try to access an external server without CORS enabled. url=" + url);
+          }
           if (onError != null) {
             onError.fe(response.getText(), "error", request, response);
           }