⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 xajaxresponse.inc.php

📁 国外的人才求职招聘最新版
💻 PHP
📖 第 1 页 / 共 2 页
字号:
<?php
///////////////////////////////////////////////////////////////////////////////
// xajaxResponse.inc.php :: xajax XML response class
//
// xajax version 0.2.3
// copyright (c) 2005 by Jared White & J. Max Wilson
// http://www.xajaxproject.org
//
// xajax is an open source PHP class library for easily creating powerful
// PHP-driven, web-based Ajax Applications. Using xajax, you can asynchronously
// call PHP functions and update the content of your your webpage without
// reloading the page.
//
// xajax is released under the terms of the LGPL license
// http://www.gnu.org/copyleft/lesser.html#SEC3
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
//
// This library 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
// Lesser General Public License for more details.
// 
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
///////////////////////////////////////////////////////////////////////////////

/*
   ----------------------------------------------------------------------------
   | Online documentation for this class is available on the xajax wiki at:   |
   | http://wiki.xajaxproject.org/Documentation:xajaxResponse.inc.php         |
   ----------------------------------------------------------------------------
*/

// The xajaxResponse class is used to created responses to be sent back to your
// webpage.  A response contains one or more command messages for updating your page.
// Currently xajax supports 18 kinds of command messages, including some common ones such as:
// * Assign - sets the specified attribute of an element in your page
// * Append - appends data to the end of the specified attribute of an element in your page
// * Prepend - prepends data to the beginning of the specified attribute of an element in your page
// * Replace - searches for and replaces data in the specified attribute of an element in your page
// * Script - runs the supplied JavaScript code
// * Alert - shows an alert box with the supplied message text
//
// *Note: elements are identified by their HTML id, so if you don't see your browser HTML display changing from the request, make sure you're using the right id names in your response.

class xajaxResponse
{
	var $xml;
	var $sEncoding;
	var $bOutputEntities;

	// Constructor. Its main job is to set the character encoding for the response.
	// $sEncoding is a string containing the character encoding string to use.
	// $bOutputEntities lets you set if you want special characters in the output
	//  converted to HTML entities
	// * Note: to change the character encoding for all of the responses, set the
	// XAJAX_DEFAULT_ENCODING constant near the beginning of the xajax.inc.php file
	function xajaxResponse($sEncoding=XAJAX_DEFAULT_CHAR_ENCODING, $bOutputEntities=false)
	{
		$this->setCharEncoding($sEncoding);
		$this->bOutputEntities = $bOutputEntities;
	}
	
	// setCharEncoding() sets the character encoding for the response based on
	// $sEncoding, which is a string containing the character encoding to use. You
	// don't need to use this method normally, since the character encoding for the
	// response gets set automatically based on the XAJAX_DEFAULT_CHAR_ENCODING
	// constant.
	function setCharEncoding($sEncoding)
	{
		$this->sEncoding = $sEncoding;
	}
	
	// outputEntitiesOn() tells the response object to convert special characters to
	// HTML entities automatically (only works if the mb_string extension is available).
	function outputEntitiesOn()
	{
		$this->bOutputEntities = true;
	}
	
	// outputEntitiesOff() tells the response object to output special characters
	// intact. (default behavior)
	function outputEntitiesOff()
	{
		$this->bOutputEntities = false;
	}
	
	// addAssign() adds an assign command message to the XML response
	// $sTarget is a string containing the id of an HTML element
	// $sAttribute is the part of the element you wish to modify ("innerHTML", "value", etc.)
	// $sData is the data you want to set the attribute to
	// usage: $objResponse->addAssign("contentDiv", "innerHTML", "Some Text");
	function addAssign($sTarget,$sAttribute,$sData)
	{
		$this->xml .= $this->_cmdXML(array("n"=>"as","t"=>$sTarget,"p"=>$sAttribute),$sData);
	}
	
	// addAppend() adds an append command message to the XML response
	// $sTarget is a string containing the id of an HTML element
	// $sAttribute is the part of the element you wish to modify ("innerHTML", "value", etc.)
	// $sData is the data you want to append to the end of the attribute
	// usage: $objResponse->addAppend("contentDiv", "innerHTML", "Some New Text");
	function addAppend($sTarget,$sAttribute,$sData)
	{	
		$this->xml .= $this->_cmdXML(array("n"=>"ap","t"=>$sTarget,"p"=>$sAttribute),$sData);
	}
	
	// addPrepend() adds an prepend command message to the XML response
	// $sTarget is a string containing the id of an HTML element
	// $sAttribute is the part of the element you wish to modify ("innerHTML", "value", etc.)
	// $sData is the data you want to prepend to the beginning of the attribute
	// usage: $objResponse->addPrepend("contentDiv", "innerHTML", "Some Starting Text");
	function addPrepend($sTarget,$sAttribute,$sData)
	{
		$this->xml .= $this->_cmdXML(array("n"=>"pp","t"=>$sTarget,"p"=>$sAttribute),$sData);
	}
	
	// addReplace() adds an replace command message to the XML response
	// $sTarget is a string containing the id of an HTML element
	// $sAttribute is the part of the element you wish to modify ("innerHTML", "value", etc.)
	// $sSearch is a string to search for
	// $sData is a string to replace the search string when found in the attribute
	// usage: $objResponse->addReplace("contentDiv", "innerHTML", "text", "<b>text</b>");
	function addReplace($sTarget,$sAttribute,$sSearch,$sData)
	{
		$sDta = "<s><![CDATA[$sSearch]]></s><r><![CDATA[$sData]]></r>";
		$this->xml .= $this->_cmdXML(array("n"=>"rp","t"=>$sTarget,"p"=>$sAttribute),$sDta);
	}
	
	// addClear() adds an clear command message to the XML response
	// $sTarget is a string containing the id of an HTML element
	// $sAttribute is the part of the element you wish to clear ("innerHTML", "value", etc.)
	// usage: $objResponse->addClear("contentDiv", "innerHTML");
	function addClear($sTarget,$sAttribute)
	{
		$this->addAssign($sTarget,$sAttribute,'');
	}
	
	// addAlert() adds an alert command message to the XML response
	// $sMsg is the text to be displayed in the Javascript alert box
	// usage: $objResponse->addAlert("This is important information");
	function addAlert($sMsg)
	{
		$this->xml .= $this->_cmdXML(array("n"=>"al"),$sMsg);
	}
	
	// addRedirect() uses the addScript() method to add a Javascript redirect to
	// another URL
	// $sURL is the URL to redirect the client browser to
	// usage: $objResponse->addRedirect("http://www.xajaxproject.org");
	function addRedirect($sURL)
	{
		//we need to parse the query part so that the values are rawurlencode()'ed
		//can't just use parse_url() cos we could be dealing with a relative URL which
		//  parse_url() can't deal with.
		$queryStart = strpos($sURL, '?', strrpos($sURL, '/'));
		if ($queryStart !== FALSE)
		{
			$queryStart++;
			$queryEnd = strpos($sURL, '#', $queryStart);
			if ($queryEnd === FALSE)
				$queryEnd = strlen($sURL);
			$queryPart = substr($sURL, $queryStart, $queryEnd-$queryStart);
			parse_str($queryPart, $queryParts);
			$newQueryPart = "";
			foreach($queryParts as $key => $value)
			{
				$newQueryPart .= rawurlencode($key).'='.rawurlencode($value).ini_get('arg_separator.output');
			}
			$sURL = str_replace($queryPart, $newQueryPart, $sURL);
		}
		$this->addScript('window.location = "'.$sURL.'";');
	}

	// addScript() adds a Javascript command message to the XML response
	// $sJS is a string containing Javascript code to be executed

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -