]> source.dussan.org Git - gwtquery.git/commitdiff
filters in Ajax.load were not working find because we were using filter() instead...
authorManolo Carrasco <manolo@apache.org>
Mon, 13 Feb 2012 12:31:39 +0000 (12:31 +0000)
committerManolo Carrasco <manolo@apache.org>
Mon, 13 Feb 2012 12:31:39 +0000 (12:31 +0000)
gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/ajax/Ajax.java

index 86f5c1cd37966703c4d6b198c05968778af7b4a2..f280b52bbae1f279adf20434c418f86b27d441aa 100644 (file)
@@ -340,8 +340,16 @@ public class Ajax extends GQuery {
     s.setData(data);
     s.setSuccess(new Function() {
       public void f() {
-        GQuery d = $(getData()[0].toString());
-        Ajax.this.empty().append(filter.isEmpty() ? d : d.filter(filter));
+        // We clean up the returned string to smoothly append it to our document 
+        String s = getData()[0].toString().replaceAll("<![^>]+>\\s*", "")
+          .replaceAll("(?si)</?html[^>]*>\\s*", "")
+          .replaceFirst("(?si)<head[^>]*>.*</head>\\s*", "")
+          .replaceFirst("(?si)<script[^>]*>.*</script>\\s*", "")
+          .replaceAll("<?si></?body[^>]*>\\s*", "");
+        // We wrap the results in a div
+        s = "<div>" + s + "</div>";
+        
+        Ajax.this.empty().append(filter.isEmpty() ? $(s) : $(s).find(filter));
         if (onSuccess != null) {
           onSuccess.setElement(Ajax.this.get(0));
           onSuccess.f();