From 6bcd12d641198fa5f01136f8a957c8768761f837 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Manuel=20Carrasco=20Mo=C3=B1ino?= Date: Mon, 5 Nov 2012 11:48:12 +0100 Subject: [PATCH] Ajax should handle statusCode == 0 as an error --- .../com/google/gwt/query/client/plugins/ajax/Ajax.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/ajax/Ajax.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/ajax/Ajax.java index 64e713db..832fda8b 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/ajax/Ajax.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/ajax/Ajax.java @@ -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); } -- 2.39.5