web/data/cubicweb.compat.js
branchtls-sprint
changeset 1563 b130c6cec8c2
parent 1419 7ff24154351d
child 2537 73c83c14dd2c
--- 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);
-//     })
-// }
 
+