--- a/web/data/cubicweb.compat.js Wed Apr 29 19:52:56 2009 +0200
+++ b/web/data/cubicweb.compat.js Wed Apr 29 19:54:50 2009 +0200
@@ -365,11 +365,16 @@
};
-function loadJSON(url, data, type) {
+/*
+ * Asynchronously load an url and return a deferred
+ * whose callbacks args are decoded according to
+ * the Content-Type response header
+ */
+function loadRemote(url, data, reqtype) {
var d = new Deferred();
jQuery.ajax({
url: url,
- type: type,
+ type: reqtype,
data: data,
beforeSend: function(xhr) {
@@ -377,6 +382,9 @@
},
success: function(data, status) {
+ if (d.req.getResponseHeader("content-type") == 'application/json') {
+ data = evalJSON(data);
+ }
d.success(data);
},
@@ -506,23 +514,7 @@
var KEYS = {
KEY_ESC: 27,
KEY_ENTER: 13
-}
+};
-// XHR = null;
-// function test() {
-// var d = loadJSON('http://crater:9876/json?mode=remote&fname=i18n&pageid=xxx&arg=' + jQuery.toJSON(['modify']));
-// d = d.addCallback(function (result, xhr) {
-// XHR = xhr;
-// log('got ajax result 1' + result + xhr);
-// log('got ajax result 1' + xhr);
-// log('got ajax result 1' + xhr + 'arguments =', arguments.length);
-// });
-// d.addCallback(function (x, req, y, z) {
-// log('callback 2 x =' + x, ' req=', req, 'y =', y, 'z=',z);
-// }, 12, 13)
-// d.addErrback(function (error, xhr) {
-// XHR = xhr;
-// log('got err', error, ' code =', xhr.status, 'arguments length=', arguments.length);
-// })
-// }
+