THRIFT-1514 Callbacks with newer jQuery versions don't work
Patch: Andrew Grumet

git-svn-id: https://svn.apache.org/repos/asf/thrift/trunk@1332619 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/lib/js/test/build.xml b/lib/js/test/build.xml
index f1aa51d..7f93d0e 100755
--- a/lib/js/test/build.xml
+++ b/lib/js/test/build.xml
@@ -93,7 +93,7 @@
   </target>
 
   <target name="jslibs" depends="init, proxy">
-    <get src="http://code.jquery.com/jquery-1.5.2.js" dest="${build}/js/lib" usetimestamp="true"/>
+    <get src="http://code.jquery.com/jquery-1.7.2.js" dest="${build}/js/lib" usetimestamp="true"/>
     <get src="http://js-test-driver.googlecode.com/svn/trunk/JsTestDriver/contrib/qunit/src/equiv.js" dest="${build}/js/lib" usetimestamp="true"/>
     <get src="http://js-test-driver.googlecode.com/svn/trunk/JsTestDriver/contrib/qunit/src/QUnitAdapter.js" dest="${build}/js/lib" usetimestamp="true"/>
 
diff --git a/lib/js/test/test.html b/lib/js/test/test.html
index c3fd0b1..9396fd5 100755
--- a/lib/js/test/test.html
+++ b/lib/js/test/test.html
@@ -27,7 +27,7 @@
   <script src="gen-js/ThriftTest.js"       type="text/javascript" charset="utf-8"></script>
 
   <!-- jQuery -->
-  <script type="text/javascript" src="build/js/lib/jquery-1.5.2.js" charset="utf-8"></script>
+  <script type="text/javascript" src="build/js/lib/jquery-1.7.2.js" charset="utf-8"></script>
   
   <!-- QUnit Test framework-->
   <script type="text/javascript" src="build/js/lib/qunit.js" charset="utf-8"></script>
diff --git a/lib/js/test/test.js b/lib/js/test/test.js
index fb36f68..ace676f 100755
--- a/lib/js/test/test.js
+++ b/lib/js/test/test.js
@@ -390,7 +390,7 @@
       ok(false);
       QUnit.start();
     })
-    .error(function(e){
+    .error(function(xhr,status,e){
       equal(e.errorCode, 1001);
       equal(e.message, "Xception");
       QUnit.start();
diff --git a/lib/js/thrift.js b/lib/js/thrift.js
index d1cf099..2de5f1a 100644
--- a/lib/js/thrift.js
+++ b/lib/js/thrift.js
@@ -223,46 +223,26 @@
             throw 'Thrift.js requires jQuery 1.5+ to use asynchronous requests';
         }
 
-        // Deferreds
-        var deferred = jQuery.Deferred();
-        var completeDfd = jQuery._Deferred();
-        var dfd = deferred.promise();
-        dfd.success = dfd.done;
-        dfd.error = dfd.fail;
-        dfd.complete = completeDfd.done;
+        var thriftTransport = this;
 
         var jqXHR = jQuery.ajax({
             url: this.url,
             data: postData,
             type: 'POST',
             cache: false,
-            dataType: 'text',
-            context: this,
-            success: this.jqResponse,
-            error: function(xhr, status, e) {
-                deferred.rejectWith(client, jQuery.merge([e], xhr.tArgs));
+            dataType: 'text thrift',
+            converters: {
+                'text thrift' : function(responseData) {
+                    thriftTransport.setRecvBuffer(responseData);
+                    var value = recv_method.call(client);
+                    return value;
+                }
             },
-            complete: function(xhr, status) {
-                completeDfd.resolveWith(client, [xhr, status]);
-            }
+            context: client,
+            success: jQuery.makeArray(args).pop()
         });
 
-        deferred.done(jQuery.makeArray(args).pop()); //pop callback from args
-        jqXHR.tArgs = args;
-        jqXHR.tClient = client;
-        jqXHR.tRecvFn = recv_method;
-        jqXHR.tDfd = deferred;
-        return dfd;
-    },
-
-    jqResponse: function(responseData, textStatus, jqXHR) {
-      this.setRecvBuffer(responseData);
-      try {
-          var value = jqXHR.tRecvFn.call(jqXHR.tClient);
-          jqXHR.tDfd.resolveWith(jqXHR, jQuery.merge([value], jqXHR.tArgs));
-      } catch (ex) {
-          jqXHR.tDfd.rejectWith(jqXHR, jQuery.merge([ex], jqXHR.tArgs));
-      }
+        return jqXHR;
     },
 
     setRecvBuffer: function(buf) {