[javascript] fix loadRemote implementation for synchronous requests
In case of synhronous requests, loadRemote is supposed to return the
"interpreted" server result (e.g a json object, a DOM object, ...).
$.ajax() always return the XHR object, so we have to use the success
callback to capture the actual server result and return it later.
--- a/web/data/cubicweb.ajax.js Tue Oct 19 17:57:56 2010 +0200
+++ b/web/data/cubicweb.ajax.js Wed Oct 20 09:03:37 2010 +0200
@@ -322,12 +322,21 @@
});
return deferred;
} else {
- var result = jQuery.ajax({
+ var result;
+ // jQuery.ajax returns the XHR object, even for synchronous requests,
+ // but in that case, the success callback will be called before
+ // jQuery.ajax returns. The first argument of the callback will be
+ // the server result, interpreted by jQuery according to the reponse's
+ // content-type (i.e. json or xml)
+ jQuery.ajax({
url: url,
type: (reqtype || 'GET').toUpperCase(),
data: form,
traditional: true,
- async: false
+ async: false,
+ success: function(res) {
+ result = res;
+ }
});
return result;
}