# HG changeset patch # User Adrien Di Mascio # Date 1287558217 -7200 # Node ID f8b36b1e98bfcf1fca35566e43e0931a86aa0bd4 # Parent d60250252fc65d15fbe30d87214eb43f75fe8e0f [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. diff -r d60250252fc6 -r f8b36b1e98bf web/data/cubicweb.ajax.js --- 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; }