Bjwebb / agplmail

AGPL'd Webmail Client

This URL has Read+Write access

agplmail / ajax.js
100644 67 lines (60 sloc) 2.029 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/*
# Copyright (C) 2008 Ben Webb <dreamer@freedomdreams.co.uk>
# This file is part of AGPLMail.
#
# AGPLMail is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# AGPLMail is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with AGPLMail. If not, see <http://www.gnu.org/licenses/>.
*/
 
args = '';
 
function GetXmlHttpObject() {
    var xmlHttp;
    try {
        // Firefox, Opera 8.0+, Safari
        xmlHttp=new XMLHttpRequest();
    }
    catch (e) {
        // Internet Explorer
        try {
            xmlHttp=new ActiveXObject(Msxml2.XMLHTTP);
        }
        catch (e) {
            try {
                xmlHttp=new ActiveXObject(Microsoft.XMLHTTP);
            }
            catch (e) {
                alert("Sorry, you need a newser browser :S");
                return false;
            }
        }
    }
    return xmlHttp;
}
 
function ajax(params, container, increment) {
    xmlHttp = GetXmlHttpObject();
    xmlHttp.onreadystatechange=function() {
        if(xmlHttp.readyState==4) {
            if (increment)
                document.getElementById(container).innerHTML += xmlHttp.responseText;
            else
                document.getElementById(container).innerHTML = xmlHttp.responseText;
        }
    }
    post(params);
}
 
function post(params) {
    xmlHttp.open("POST","index.php?do=ajax",true);
    
    xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    xmlHttp.setRequestHeader("Content-length", params.length);
    xmlHttp.setRequestHeader("Connection", "close");
 
    xmlHttp.send(params);
}