"TYPO3 4.0.1: typo3_src-4.0.1/t3lib/class.t3lib_ajax.php Source File", "datetime" => "Sat Dec 2 19:22:17 2006", "date" => "2 Dec 2006", "doxygenversion" => "1.4.6", "projectname" => "TYPO3 4.0.1", "projectnumber" => "4.0.1" ); get_header($doxygen_vars); ?>

class.t3lib_ajax.php

00001 <?php
00002 /***************************************************************
00003 *  Copyright notice
00004 *
00005 *  (c) 2004-2005 Kasper Skaarhoj (kasperYYYY@typo3.com)
00006 *  All rights reserved
00007 *
00008 *  This script is part of the TYPO3 project. The TYPO3 project is
00009 *  free software; you can redistribute it and/or modify
00010 *  it under the terms of the GNU General Public License as published by
00011 *  the Free Software Foundation; either version 2 of the License, or
00012 *  (at your option) any later version.
00013 *
00014 *  The GNU General Public License can be found at
00015 *  http://www.gnu.org/copyleft/gpl.html.
00016 *  A copy is found in the textfile GPL.txt and important notices to the license
00017 *  from the author is found in LICENSE.txt distributed with these scripts.
00018 *
00019 *
00020 *  This script is distributed in the hope that it will be useful,
00021 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00022 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00023 *  GNU General Public License for more details.
00024 *
00025 *  This copyright notice MUST APPEAR in all copies of the script!
00026 ***************************************************************/
00047 class t3lib_ajax {
00059         function getJScode($handlerFunction, $fallback='', $debug=0)    {
00060                         // Init the XMLHTTP request object
00061                 $code = '
00062                 function ajax_initObject()      {
00063                         var A;
00064                         try     {
00065                                 A=new ActiveXObject("Msxml2.XMLHTTP");
00066                         } catch (e)     {
00067                                 try     {
00068                                         A=new ActiveXObject("Microsoft.XMLHTTP");
00069                                 } catch (oc)    {
00070                                         A=null;
00071                                 }
00072                         }
00073                         if(!A && typeof XMLHttpRequest != "undefined")  {
00074                                 A = new XMLHttpRequest();
00075                         }
00076                         return A;
00077                 }';
00078                         // in case AJAX is not available, fallback function
00079                 if($fallback)   {
00080                         $fallback .= '(url)';
00081                 } else {
00082                         $fallback = 'return';
00083                 }
00084                 $code .= '
00085                 function ajax_doRequest(url)    {
00086                         var x;
00087 
00088                         x = ajax_initObject();
00089                         if(!x)  {
00090                                 '.$fallback.';
00091                         }
00092                         x.open("GET", url, true);
00093 
00094                         x.onreadystatechange = function()       {
00095                                 if (x.readyState != 4)  {
00096                                         return;
00097                                 }
00098                                 '.($debug?'alert(x.responseText)':'').'
00099                                 var xmldoc = x.responseXML;
00100                                 var t3ajax = xmldoc.getElementsByTagName("t3ajax")[0];
00101                                 '.$handlerFunction.'(t3ajax);
00102                         }
00103                         x.send("");
00104 
00105                         delete x;
00106                 }';
00107 
00108                 return $code;
00109         }
00110 
00117         function outputXMLreply($innerXML)      {
00118                         // AJAX needs some XML data
00119                 header('Content-Type: text/xml');
00120                 $xml = '<?xml version="1.0"?>
00121 <t3ajax>'.$innerXML.'</t3ajax>';
00122                 echo $xml;
00123         }
00124 
00125 }
00126 
00127 
00128 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_ajax.php'])      {
00129         include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_ajax.php']);
00130 }
00131 ?>