From: Manolo Carrasco Date: Mon, 13 Feb 2012 12:56:58 +0000 (+0000) Subject: Adding static getJSONP method to GQuery class X-Git-Tag: release-1.3.2~116 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=4fdaee8af1cd042ff6839aaa8618312df02d13e5;p=gwtquery.git Adding static getJSONP method to GQuery class --- diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/GQuery.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/GQuery.java index c837f47f..03b50d65 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/GQuery.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/GQuery.java @@ -542,6 +542,34 @@ public class GQuery implements Lazy { final Function onSuccess) { Ajax.getJSON(url, data, onSuccess); } + + /** + * Perform an ajax request to the server using scripts tags and + * parsing the json response. The request is not subject to the + * same origin policy restrictions. + * + * Server side should accept a parameter to specify the callback + * funcion name, and it must return a valid json object wrapped + * this callback function. + * + * Example: +
+    Client code:
+    getJSONP("http://server.exampe.com/getData.php",$$("myCallback:'?', otherParameter='whatever'"), 
+      new Function(){ public void f() {
+        Properties p = getDataProperties();
+        alert(p.getStr("k1");
+    }});
+   
+    Server response:
+    myCallback({"k1":"v1", "k2":"v2"});
+   
+ * + */ + public static void getJSONP(String url, Properties data, + final Function onSuccess) { + Ajax.getJSONP(url, data, onSuccess); + } protected static DocumentStyleImpl getStyleImpl(){ if (styleImpl == null){ diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/LazyEvents.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/LazyEvents.java index 2e8bac07..7584f571 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/LazyEvents.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/LazyEvents.java @@ -17,6 +17,7 @@ package com.google.gwt.query.client.plugins; import com.google.gwt.dom.client.Element; import com.google.gwt.dom.client.NativeEvent; import com.google.gwt.dom.client.Node; +import com.google.gwt.event.dom.client.KeyCodes; import com.google.gwt.query.client.Function; import com.google.gwt.query.client.GQuery; import com.google.gwt.query.client.js.JsUtils; 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 f280b52b..0f991163 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 @@ -119,9 +119,8 @@ public class Ajax extends GQuery { final String dataType = settings.getDataType(); if ("jsonp".equalsIgnoreCase(dataType)) { - Method httpMethod = resolveHttpMethod(settings); String data = resolveData(settings); - String url = resolveUrl(settings, httpMethod, data); + String url = resolveUrl(settings, RequestBuilder.GET, data); int timeout = settings.getTimeout(); getJSONP(url, onSuccess, onError, timeout); return; @@ -306,7 +305,7 @@ public class Ajax extends GQuery { } public static void getJSONP(String url, Function success, Function error, int timeout) { - if (!url.contains("=?")) { + if (!url.contains("=?") && !url.contains("callback=")) { url += (url.contains("?") ? "&" : "?") + "callback=?"; } url += "&_=" + System.currentTimeMillis();