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

📄 xajaxresponse.inc.php

📁 国外的人才求职招聘最新版
💻 PHP
📖 第 1 页 / 共 2 页
字号:
	// usage: $objResponse->addScript("var x = prompt('get some text');");
	function addScript($sJS)
	{
		$this->xml .= $this->_cmdXML(array("n"=>"js"),$sJS);
	}
	
	// addRemove() adds a remove element command message to the XML response
	// $sTarget is a string containing the id of an HTML element to be removed
	// from your page
	// usage: $objResponse->addRemove("Div2");
	function addRemove($sTarget)
	{
		$this->xml .= $this->_cmdXML(array("n"=>"rm","t"=>$sTarget),'');
	}
	
	// addCreate() adds a create element command message to the XML response
	// $sParent is a string containing the id of an HTML element to which the new
	// element will be appended.
	// $sTag is the tag to be added
	// $sId is the id to be assigned to the new element
	// $sType has been deprecated, use the addCreateInput() method instead
	// usage: $objResponse->addCreate("parentDiv", "h3", "myid");
	function addCreate($sParent, $sTag, $sId, $sType="")
	{
		if ($sType)
		{
			trigger_error("The \$sType parameter of addCreate has been deprecated.  Use the addCreateInput() method instead.", E_USER_WARNING);
			return;
		}
		$this->xml .= $this->_cmdXML(array("n"=>"ce","t"=>$sParent,"p"=>$sId),$sTag);
	}
	
	// addInsert() adds an insert element command message to the XML response
	// $sBefore is a string containing the id of the child before which the new element
	// will be inserted
	// $sTag is the tag to be added
	// $sId is the id to be assigned to the new element
	// usage: $objResponse->addInsert("childDiv", "h3", "myid");
	function addInsert($sBefore, $sTag, $sId)
	{
		$this->xml .= $this->_cmdXML(array("n"=>"ie","t"=>$sBefore,"p"=>$sId),$sTag);
	}

	// addInsertAfter() adds an insert element command message to the XML response
	// $sAfter is a string containing the id of the child after which the new element
	// will be inserted
	// $sTag is the tag to be added
	// $sId is the id to be assigned to the new element
	// usage: $objResponse->addInsertAfter("childDiv", "h3", "myid");	
	function addInsertAfter($sAfter, $sTag, $sId)
	{
		$this->xml .= $this->_cmdXML(array("n"=>"ia","t"=>$sAfter,"p"=>$sId),$sTag);
	}
	
	// addCreateInput() adds a create input command message to the XML response
	// $sParent is a string containing the id of an HTML element to which the new
	// input will be appended
	// $sType is the type of input to be created (text, radio, checkbox, etc.)
	// $sName is the name to be assigned to the new input and the variable name when it is submitted
	// $sId is the id to be assigned to the new input
	// usage: $objResponse->addCreateInput("form1", "text", "username", "input1");
	function addCreateInput($sParent, $sType, $sName, $sId)
	{
		$this->xml .= $this->_cmdXML(array("n"=>"ci","t"=>$sParent,"p"=>$sId,"c"=>$sType),$sName);
	}
	
	// addInsertInput() adds an insert input command message to the XML response
	// $sBefore is a string containing the id of the child before which the new element
	// will be inserted
	// $sType is the type of input to be created (text, radio, checkbox, etc.)
	// $sName is the name to be assigned to the new input and the variable name when it is submitted
	// $sId is the id to be assigned to the new input
	// usage: $objResponse->addInsertInput("input5", "text", "username", "input1");
	function addInsertInput($sBefore, $sType, $sName, $sId)
	{
		$this->xml .= $this->_cmdXML(array("n"=>"ii","t"=>$sBefore,"p"=>$sId,"c"=>$sType),$sName);
	}
	
	// addEvent() adds an event command message to the XML response
	// $sTarget is a string containing the id of an HTML element
	// $sEvent is the event you wish to set ("click", "mouseover", etc.)
	// $sScript is the Javascript string you want to the event to invoke
	// usage: $objResponse->addEvent("contentDiv", "click", "alert(\'Hello World\');");
	function addEvent($sTarget,$sEvent,$sScript)
	{
		$this->xml .= $this->_cmdXML(array("n"=>"ev","t"=>$sTarget,"p"=>$sEvent),$sScript);
	}
	
	// addHandler() adds a handler command message to the XML response
	// $sTarget is a string containing the id of an HTML element
	// $sEvent is the event you wish to set ("click", "mouseover", etc.)
	// $sHandler is a string containing the name of a Javascript function
	// that will handle the event. Multiple handlers can be added for the same event
	// usage: $objResponse->addHandler("contentDiv", "click", "content_click");
	function addHandler($sTarget,$sEvent,$sHandler)
	{	
		$this->xml .= $this->_cmdXML(array("n"=>"ah","t"=>$sTarget,"p"=>$sEvent),$sHandler);
	}
	
	// addRemoveHandler() adds a remove handler command message to the XML response
	// $sTarget is a string containing the id of an HTML element
	// $sEvent is the event you wish to remove ("click", "mouseover", etc.)
	// $sHandler is a string containing the name of a Javascript handler function
	// that you want to remove
	// usage: $objResponse->addRemoveHandler("contentDiv", "click", "content_click");
	function addRemoveHandler($sTarget,$sEvent,$sHandler)
	{	
		$this->xml .= $this->_cmdXML(array("n"=>"rh","t"=>$sTarget,"p"=>$sEvent),$sHandler);
	}
	
	// addIncludeScript() adds an include script command message to the XML response
	// $sFileName is a URL of the Javascript file to include
	// usage: $objResponse->addIncludeScript("functions.js");
	function addIncludeScript($sFileName)
	{
		$this->xml .= $this->_cmdXML(array("n"=>"in"),$sFileName);
	}
	
	// getXML() returns the XML to be returned from your function to the xajax
	// processor on your page. Since xajax 0.2, you can also return an xajaxResponse
	// object from your function directly, and xajax will automatically request the
	// XML using this method call.
	// usage: return $objResponse->getXML();
	function getXML()
	{
		$sXML = "<?xml version=\"1.0\"";
		if ($this->sEncoding && strlen(trim($this->sEncoding)) > 0)
			$sXML .= " encoding=\"".$this->sEncoding."\"";
		$sXML .= " ?"."><xjx>" . $this->xml . "</xjx>";
		
		return $sXML;
	}
	
	// loadXML() adds the commands of the provided response XML output to this
	// response object
	// $sXML is the response XML (returned from a getXML() method) to add to the
	// end of this response object
	// usage: $r1 = $objResponse1->getXML();
	//        $objResponse2->loadXML($r1);
	//        return $objResponse2->getXML();
	function loadXML($mXML)
	{
		if (is_a($mXML, "xajaxResponse")) {
			$mXML = $mXML->getXML();
		}
		$sNewXML = "";
		$iStartPos = strpos($mXML, "<xjx>") + 5;
		$sNewXML = substr($mXML, $iStartPos);
		$iEndPos = strpos($sNewXML, "</xjx>");
		$sNewXML = substr($sNewXML, 0, $iEndPos);
		$this->xml .= $sNewXML;
	}

	// private method, used internally
	function _cmdXML($aAttributes, $sData)
	{
		if ($this->bOutputEntities) {
			if (function_exists('mb_convert_encoding')) {
				$sData = call_user_func_array('mb_convert_encoding', array(&$sData, 'HTML-ENTITIES', $this->sEncoding));
			}
			else {
				trigger_error("The xajax XML response output could not be converted to HTML entities because the mb_convert_encoding function is not available", E_USER_NOTICE);
			}
		}
		$xml = "<cmd";
		foreach($aAttributes as $sAttribute => $sValue)
			$xml .= " $sAttribute=\"$sValue\"";
		if ($sData !== null && !stristr($sData,'<![CDATA['))
			$xml .= "><![CDATA[$sData]]></cmd>";
		else if ($sData !== null)
			$xml .= ">$sData</cmd>";
		else
			$xml .= "></cmd>";
		
		return $xml;
	}
	
}// end class xajaxResponse
?>

⌨️ 快捷键说明

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