From: Florent Bruneau Date: Fri, 7 Nov 2008 17:32:11 +0000 (+0100) Subject: Rewrite our pour implementation of Ajax using jQuery. X-Git-Tag: xorg/0.10.0~34 X-Git-Url: http://git.polytechnique.org/?a=commitdiff_plain;h=053c41fc995d20a34f638106eb58158cde266cee;p=platal.git Rewrite our pour implementation of Ajax using jQuery. Signed-off-by: Florent Bruneau --- diff --git a/ChangeLog b/ChangeLog index 00c4878..c55d219 100644 --- a/ChangeLog +++ b/ChangeLog @@ -15,6 +15,9 @@ New: Bug/Wish: + * Admin: + - #912: Fix error when validating an 'alread-validated' request -FRU + * Core: - #918: Use POST for wiki preview -FRU diff --git a/htdocs/javascript/ajax.js b/htdocs/javascript/ajax.js index a5c5982..0f55506 100644 --- a/htdocs/javascript/ajax.js +++ b/htdocs/javascript/ajax.js @@ -20,67 +20,23 @@ function AjaxEngine() { - this.xml_client = null; - this.init = false; - this.obj = null; - this.func = null; - - this.prepare_client = function() - { - if (!this.init) { - if (window.XMLHttpRequest) { - this.xml_client = new XMLHttpRequest(); - } else if (window.ActiveXObject) { - try { - this.xml_client = new ActiveXObject("Msxml2.XMLHTTP"); - } catch (e) { - this.xml_client = new ActiveXObject("Microsoft.XMLHTTP"); - } - } - if (this.xml_client == null) { - alert("Ton client ne supporte pas Ajax, nécessaire pour certaines fonctionalités de cette page"); - } - } - this.init = true; - } - this.update_html = function(obj, src, func) { - this.prepare_client(); - if (this.xml_client == null) { - return true; - } - if (src.match(/^http/i) == null) { - src = platal_baseurl + src; - } - this.obj = obj; - this.func = func; - this.xml_client.abort(); - this.xml_client.onreadystatechange = this.apply_update_html(this); - this.xml_client.open ('GET', src, true); - this.xml_client.send (null); - return false; - } - - this.apply_update_html = function(ajax) - { - return function() - { - if(ajax.xml_client.readyState == 4) { - if (ajax.xml_client.status == 200) { - if (ajax.obj != null) { - document.getElementById(ajax.obj).innerHTML = ajax.xml_client.responseText; + $.get(src, + function(data, textStatus) { + if (textStatus == "success") { + if (obj) { + $('#' + obj).html(data); } - if (ajax.func != null) { - ajax.func(ajax.xml_client.responseText); + if (func) { + func(data); } - } else if (ajax.xml_client.status == 403) { - window.location.reload(); - } else if (ajax.xml_client.status >= 500) { - alert("Une erreur s'est produite lors du traitement de la requête"); + } else if (textStatus == "error") { + alert("Une erreur s'est produite lors du traitement de la requête.\n" + +"Ta session a peut-être expirée."); } - } - }; + }, 'text'); + return false; } }