aboutsummaryrefslogtreecommitdiffstats
path: root/plugins/grum_plugins_classes-2/ajax.js
blob: 1b80081912f5104775e40a24673eef20327a448e (plain)
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
/* -----------------------------------------------------------------------------
  file: ajax.js
  file version: 1.1.0
  date: 2008-05-25
  ------------------------------------------------------------------------------
  author: grum at grum.dnsalias.com
  << May the Little SpaceFrog be with you >>
  ------------------------------------------------------------------------------

   this classes provides base functions to add ajax into html page

    + create_httpobject provide a simple function to create an HTML request to a
      server ; return an XMLHttpRequest object (or compatible object for IE)

    + tHttpObject is a class providing :
        - an XMLHttpRequest object
        - 

  ------------------------------------------------------------------------------
  HISTORY VERSION
  v1.0.1  + [create_httpobject] overrideMimeType unknown by IE 7.0 ;
  v1.1.0  + add create_httpobject2 with mimetype parameter
              
   -------------------------------------------------------------------------- */


  function create_httpobject(requesttype, charset, ajaxurl, async)
  {
    return(create_httpobject2(requesttype, charset, ajaxurl, async, ''));
  }

  function create_httpobject2(requesttype, charset, ajaxurl, async, mimetype)
  {
    if (window.XMLHttpRequest)
    {
      // IE7 & FF method
      http_request = new XMLHttpRequest();
    }
    else
    {
      //Other IE method.....
      if (window.ActiveXObject)
      {
        try
        {
          http_request = new ActiveXObject("Msxml2.XMLHTTP");
        }
        catch (e)
        {
          try
          {
            http_request = new ActiveXObject("Microsoft.XMLHTTP");
          }
          catch (e)
          {
            window.alert("Your browser is unable to use XMLHTTPRequest");
          } // try-catch
        } // try-catch
      }
    } // if-else

    if(charset=='') { charset='utf-8'; }

    http_request.onreadystatechange = function() {  };
    http_request.open(requesttype.toUpperCase(), ajaxurl, async);

    if(mimetype=='')
    {
      mimetype='text/html';
    }

    try
    {
      http_request.overrideMimeType(mimetype+'; charset='+charset);
    }
    catch(e)
    {
    }

    if(requesttype.toUpperCase()=='POST')
    {
      http_request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    }

    //method to restitute an XML object ; needed for compatibility between FF&IE
    http_request.XML = httpobject_responseXML;

    return(http_request);
  }


  function httpobject_responseXML()
  {
    if (document.implementation && document.implementation.createDocument)
    {
      //ff method
      return(this.responseXML);
    }
    else
    {
      //ie method
      return(xmlCreateFromString(this.responseText));
    }
  }