5d34faffecb5cf867d6649b71dac693503affa5d
[platal.git] / htdocs / javascript / ajax.js
1 /***************************************************************************
2 * Copyright (C) 2003-2006 Polytechnique.org *
3 * http://opensource.polytechnique.org/ *
4 * *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
9 * *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
14 * *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the Free Software *
17 * Foundation, Inc., *
18 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
19 ***************************************************************************/
20
21 Ajax = {
22 xml_client: null,
23 init: false,
24
25 prepare_client: function()
26 {
27 if (!Ajax.init) {
28 if (window.XMLHttpRequest) {
29 Ajax.xml_client = new XMLHttpRequest();
30 } else if (window.ActiveXObject) {
31 try {
32 Ajax.xml_client = new ActiveXObject("Msxml2.XMLHTTP");
33 } catch (e) {
34 Ajax.xml_client = new ActiveXObject("Microsoft.XMLHTTP");
35 }
36 }
37 if (Ajax.xml_client == null) {
38 alert("Ton client ne supporte pas Ajax, nécessaire pour certaines fonctionalités de cette page");
39 }
40 }
41 Ajax.init = true;
42 },
43
44 update_html: function(obj, src)
45 {
46 Ajax.prepare_client();
47 if (Ajax.xml_client == null) {
48 return true;
49 }
50 Ajax.xml_client.abort();
51 Ajax.xml_client.onreadystatechange = function()
52 {
53 if(Ajax.xml_client.readyState == 4) {
54 if (Ajax.xml_client.status == 200) {
55 if (obj != null) {
56 document.getElementById(obj).innerHTML = Ajax.xml_client.responseText;
57 }
58 } else if (Ajax.xml_client.status == 403) {
59 window.location.reload();
60 }
61 }
62 };
63 Ajax.xml_client.open ('GET', src, true);
64 Ajax.xml_client.send (null);
65 return false;
66 }
67 }
68