[ Index ]
 

Code source de vtiger CRM 5.0.2

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/include/js/ -> ajax.js (source)

   1  /*
   2      Copyright 2005 Rolando Gonzalez (rolosworld@gmail.com)
   3  
   4      This program is free software; you can redistribute it and/or modify
   5      it under the terms of the GNU General Public License as published by
   6      the Free Software Foundation; either version 2 of the License, or
   7      (at your option) any later version.
   8  
   9      This program is distributed in the hope that it will be useful,
  10      but WITHOUT ANY WARRANTY; without even the implied warranty of
  11      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12      GNU General Public License for more details.
  13  
  14      You should have received a copy of the GNU General Public License
  15      along with this program; if not, write to the Free Software
  16      Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
  17  */
  18  
  19  function getRequester()
  20  {
  21    try
  22    {
  23        if(window.XMLHttpRequest) 
  24        {
  25            return new XMLHttpRequest();
  26        } 
  27        else if(window.ActiveXObject)
  28        {
  29           try 
  30           {
  31                 return new ActiveXObject("Microsoft.XMLHTTP");
  32           } catch (e) 
  33           {
  34                 try {
  35                      return new ActiveXObject("Msxml2.XMLHTTP");
  36                 } catch (e) {return false;}
  37           }          
  38        }
  39    }
  40    catch (e) 
  41    {
  42        return false;
  43        //alert("You need a browser which supports an XMLHttpRequest Object.\nMozilla build 0.9.5 has this Object and IE5 and above.");
  44    }
  45  }
  46  
  47  /*
  48  onreadystatechange    Event handler for an event that fires at every state change
  49  readyState    Object status integer:
  50  0 = uninitialized
  51  1 = loading
  52  2 = loaded
  53  3 = interactive
  54  4 = complete
  55  responseText    String version of data returned from server process
  56  responseXML    DOM-compatible document object of data returned from server process
  57  status    Numeric code returned by server, such as 404 for "Not Found" or 200 for "OK"
  58  statusText    String message accompanying the status code
  59  */
  60  function VtigerAjax(cb)
  61  {
  62    var me = this;
  63    this.requester = getRequester();
  64    
  65    if(cb)
  66      this.callback = cb;
  67    else
  68      this.callback = function(req)
  69      {
  70        return eval(req.responseText);
  71      }
  72  
  73    this.requester.onreadystatechange = function(){
  74      switch(me.requester.readyState)
  75      {
  76        case 1:
  77        case 2:
  78        case 3:
  79          break;
  80        case 4:
  81          var response = me.callback(me.requester);
  82          break;
  83        default:
  84          alert("Error");
  85          break;
  86      }
  87    }
  88  
  89    this.state = function()
  90    {
  91      return me.requester.readyState;
  92    }
  93  
  94    this.process = function(url, parameters){
  95      me.requester.open("POST", url, true);
  96      me.requester.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
  97      me.requester.setRequestHeader("Content-length", parameters.length);
  98      me.requester.setRequestHeader("Connection", "close");
  99      me.requester.send(parameters);
 100    }
 101  }


Généré le : Sun Feb 25 10:22:19 2007 par Balluche grâce à PHPXref 0.7