麻豆小视频在线观看_中文黄色一级片_久久久成人精品_成片免费观看视频大全_午夜精品久久久久久久99热浪潮_成人一区二区三区四区

首頁(yè) > 開(kāi)發(fā) > AJAX > 正文

Xajax中文手冊(cè)(第一版)

2024-09-01 08:15:07
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友
原文:http://xajax.sourceforge.net/
英文原版:Copyright © 2005 J. Max Wilson
簡(jiǎn)體中文翻譯:HonestQiao(喬楚)/2005-12-7 17:23/(第一版)
  • 什么是xajax?
  • xajax如何工作?
  • 為什么我要使用xajax代替其他PHP的Ajax庫(kù)?
  • 如何在我的PHP腳本之中使用xajax?
  • 如何異步更新內(nèi)容?
  • 如何異步處理表單數(shù)據(jù)?
  • 如何給xajax增加定制功能?
  • 我能在私有或者收費(fèi)產(chǎn)品之中使用xajax嗎?
 
  • What is xajax?
  • How does xajax work?
  • Why should I use xajax instead of another Ajax library for PHP?
  • How do I use xajax in my PHP script?
  • How do I update my content asynchronously?
  • How do I process form data asynchronously?
  • How do I add custom functionality to xajax?
  • May I use xajax in a proprietary product and charge for it?
什么是xajax?
Xajax是一個(gè)開(kāi)源的 PHP 類(lèi)庫(kù) 它能夠讓你黏合HTML、CSS、javascript和PHP,輕而易舉的開(kāi)發(fā)功能強(qiáng)大、基于WEB的AJAX應(yīng)用軟件. 使用xajax開(kāi)發(fā)的應(yīng)用軟件,無(wú)需重新調(diào)入頁(yè)面,就能夠異步調(diào)用服務(wù)器端的PHP函數(shù)和更新內(nèi)容.
What is xajax?
xajax is an open source PHP class library that allows you to easily create powerful, web-based, Ajax applications using HTML, CSS, javascript, and PHP. Applications developed with xajax can asynchronously call server-side PHP functions and update content without reloading the page.
 
xajax 如何工作?
你的應(yīng)用軟件需要異步調(diào)用的PHP函數(shù), xajax的PHP對(duì)象都生成了對(duì)應(yīng)的封裝好了的javascript函數(shù). 當(dāng)被調(diào)用時(shí),封裝的函數(shù)使用javascript的XMLHttpRequest對(duì)象與服務(wù)器異步通訊,調(diào)用xajax對(duì)象對(duì)應(yīng)的PHP函數(shù). 調(diào)用結(jié)束后, PHP函數(shù)由xajax返回一個(gè)xajax的XML響應(yīng)傳遞給應(yīng)用程序. XML響應(yīng)包含了特定的指令和數(shù)據(jù),他們可以被xajax的javascript消息分析器解析,并且被用于更新你的應(yīng)用程序的內(nèi)容.
How does xajax work?
The xajax PHP object generates javascript wrapper functions for the PHP functions you want to be able to call asynchronously from your application. When called, these wrapper functions use javascript's XMLHttpRequest object to asynchronously communicate with the xajax object on the server which calls the corresponding PHP functions. Upon completion, an xajax XML response is returned from the PHP functions, which xajax passes back to the application. The XML response contains instructions and data that are parsed by xajax's javascript message pump and used to update the content of your application.
為什么我要使用xajax代替其他PHP的ajax庫(kù)?
你應(yīng)該選擇一個(gè)最是和你的項(xiàng)目需要的庫(kù).
xajax 提供了以下的功能, 它們使得ajax富有特色而又功能強(qiáng)大:
Why should I use xajax instead of another Ajax library for PHP?
You should choose whatever library will best meet the needs of your project.
xajax offers the following features that, together, make it unique and powerful:
  • Xajax特殊的 XML 響應(yīng) / javascript 消息分析系統(tǒng) 幫助你做到, 自動(dòng)的處理函數(shù)返回的數(shù)據(jù),按照PHP函數(shù)返回的指令更新內(nèi)容或者狀態(tài). 因?yàn)閤ajax作了這些工作Because xajax does the work, 你不需要寫(xiě)javascript的回調(diào)處理函數(shù).
  • xajax's unique XML response / javascript message-pump system does the work for you, automatically handling the data returned from your functions and updating your content or state according to the instructions you return from your PHP functions. Because xajax does the work, you don't have to write javascript callback handler functions.
  • Xajax反對(duì)將代碼和數(shù)據(jù)緊密地雜糅在一起的主張, 并且保持xajax的代碼從與他代碼分離. 因?yàn)樗菍?duì)象構(gòu)造的, 你可以加上自己定制的功能給xajax去擴(kuò)展xajaxResponse 類(lèi)和使用addScript方法.
  • xajax is object oriented to maintain tighter relationships between the code and data, and to keep the xajax code separate from other code. Because it is object oriented, you can add your own custom functionality to xajax by extending the xajaxResponse class and using the addScript() method.
  • xajax 可以工作在 Firefox, Mozilla, 大部分基于 Mozilla 的瀏覽器, Internet Explorer, 和 Safari.
  • xajax works in Firefox, Mozilla, probably other Mozilla based browsers, Internet Explorer, and Safari.
  • 除了更新元素的值和內(nèi)含的HTML內(nèi)容(innerHTML), xajax 還能用于更新樣式(styles), css 類(lèi), 多選和單選按鈕選擇,甚至可以更新任何元素的屬性.
  • In addition to updating element values and innerHTML, xajax can be used to update styles, css classes, checkbox and radio button selection, or nearly any other element attribute.
  • xajax 支持使用一維或者多維數(shù)組、關(guān)聯(lián)數(shù)組(哈希數(shù)組) 作為xajax函數(shù)的參數(shù)從javascript傳送給PHP. 反之Additionally, 如果你傳送一個(gè)javascript的對(duì)象給xajax函數(shù),PHP函數(shù)將接受一個(gè)描敘對(duì)象屬性的關(guān)聯(lián)數(shù)組(哈希數(shù)組).
  • xajax supports passing single and multidimensional arrays and associative arrays from javascript to PHP as parameters to your xajax functions. Additionally, if you pass a javascript object into an xajax function, the PHP function will receive an associative array representing the properties of the object.
  • xajax 提供了一種簡(jiǎn)單的異步表單處理方式. 使用 xajax.getFormValues() javascript 方法, 你可以輕而易舉的在表單之中提交一個(gè)描繪值的數(shù)組作為參數(shù)傳送到xajax異步處理函數(shù):
xajax_processForm(xajax.getFormValues('formId');
. 它可以處理復(fù)雜的input 元素名稱(chēng) ,例如 "checkbox[][]" 或者 "name[first]" 產(chǎn)生的多維或者關(guān)聯(lián)數(shù)組(哈希數(shù)組), 就是普通提交表單那樣使用PHP的$_GET數(shù)組
  • xajax provides easy asynchronous Form processing. By using the xajax.getFormValues() javascript method, you can easily submit an array representing the values in a form as a parameter to a xajax asynchronous function:
xajax_processForm(xajax.getFormValues('formId');
. It even works with complex input names like "checkbox[][]" and "name[first]" to produce multidimensional and associative arrays, just as if you had submitted the form and used the PHP $_GET array
  • 使用xajax你可以動(dòng)態(tài)的發(fā)送附加的javascript作為請(qǐng)求的響應(yīng)到你的應(yīng)用軟件中運(yùn)行,而這就和動(dòng)態(tài)的更新元素的屬性一樣方便.
  • Using xajax you can dynamically send additional javascript to your application to be run in response to a request as well as dynamically update element attributes.
  • Xajax會(huì)自動(dòng)比較PHP函數(shù)返回的數(shù)據(jù)與你已經(jīng)標(biāo)記需要修改的元素屬性. 只有當(dāng)新的數(shù)據(jù)確實(shí)可以改變現(xiàn)有的屬性,屬性才會(huì)真的被更新. 這將可消除程序在一定時(shí)間間隔內(nèi)更新與當(dāng)前內(nèi)容相同或者不同的內(nèi)容而出現(xiàn)的明顯的閃爍.
  • xajax automatically compares the data returned from the PHP functions to the data that is already in the attribute of the element you have marked for change. The attribute is only updated with the new data if it will actually change what is already in the attribute. This eliminates the flicker often observed in applications that update content at a regular time interval with data which may or may not differ from extant content.
  • 每一個(gè)通過(guò)xajax簡(jiǎn)單注冊(cè)的函數(shù)都可以有不同的請(qǐng)求方式. 所有的函數(shù)默認(rèn)使用POST方式,除非你明確的指定使用GET方式. 如果使用GET請(qǐng)求,你必須非常明確的考慮它確實(shí)是你所需要的
  • Each function registered to be accessible through xajax can have a different request type. All functions default to use POST unless GET is explicitly set. This is to encourage careful consideration of when to use GET requests
  • 如果沒(méi)有指定URI,xajax將設(shè)法自動(dòng)確定腳本的URI. Xajax的自動(dòng)確定算法經(jīng)過(guò)了充分的驗(yàn)證,確保在大部分HTTPS或者未知端口的HTTP服務(wù)器上也可以正常的工作.
  • If no request URI is specified, xajax tries to autodetect the URL of the script. The xajax autodetection algorithm is sophisticated enough that, on most servers, it will work under a secure https:// protocol as well as http:// and with nonstandard ports.
  • Xajax使用UTF8編碼所有的請(qǐng)求和響應(yīng),以確保支持絕大部分的字符和語(yǔ)言. Xajax已經(jīng)成功測(cè)試了多種不同的UNICODE字符,包括Spanish, Russian, Arabic, and Hebrew
  • xajax encodes all of its requests and responses in UTF-8 so that it can support a wider range of characters and languages. xajax has been successfully tested with various unicode characters including Spanish, Russian, Arabic, and Hebrew
  • 幾乎所有xajax生成的javascript都可以通過(guò)動(dòng)態(tài)的外部javascript包含到你的web程序之中. 當(dāng)你在瀏覽器之中查看程序的源代碼時(shí),不會(huì)有javascript的函數(shù)定義混雜在HTML標(biāo)記之中.
  • Nearly all of the javascript generated by xajax is included into your web application through dynamic external javascript. When you view the source of your application in your browser, the markup will be not cluttered by javascript function definitions.
  • Xajax可以使用在Smarty模板系統(tǒng)之中,僅僅需要?jiǎng)?chuàng)建一個(gè)smarty變量就可以包含xajax的javascript:
$smarty->assign('xajax_javascript', $xajax->getjavascript());
然后你可以使用在header模版之中使用
{$xajax_javascript}
從而把xajax應(yīng)用到你的站點(diǎn).
  • xajax can be used with the Smarty templating system by creating a variable in smarty that contains the xajax javascript:
$smarty->assign('xajax_javascript', $xajax->getjavascript());
Then you can use
{$xajax_javascript}
in your header template to use xajax on your site.
如何在我的PHP腳本之中使用xajax?
Xajax的設(shè)計(jì)是如此的富有特色,以至于不管是已有的web程序還是新的項(xiàng)目,它都能夠被極其簡(jiǎn)單的部署和應(yīng)用. 僅僅需要七步,你就可以在幾乎任何PHP腳本之中加入xajax的強(qiáng)大功能:
How do I use xajax in my PHP script?
xajax is designed to be extremely easy to implement in both existing web applications as well as new projects. You can add the power of xajax to nearly any PHP script in seven easy steps:
  1. 包含xajax類(lèi)庫(kù):
require_once("xajax.inc.php");
  1. 實(shí)例化xajax 對(duì)象:
$xajax = new xajax();
  1. 注冊(cè)你需要通過(guò)xajax調(diào)用的PHP函數(shù)的名稱(chēng):
$xajax->registerFunction("myFunction");
  1. 編寫(xiě)注冊(cè)的PHP函數(shù),并且在函數(shù)之中使用xajaxResponse 對(duì)象返回XML指令:
function myFunction($arg)
{
   // 對(duì)$arg做一些基本處理例如從數(shù)據(jù)庫(kù)檢索數(shù)據(jù)
   // 然后把結(jié)果賦值給變量,例如$newContent
  
   // 實(shí)例化xajaxResponse 對(duì)象
   $objResponse = new xajaxResponse();
  
   // 添加指令到響應(yīng)之中,用于指派
   //指定元素(例如id="SomeElementId")的innerHTML屬性的新的內(nèi)容
   $objResponse->addAssign("SomeElementId","innerHTML", $newContent);
  
   //返回xajaxResponse 對(duì)象生成的XML響應(yīng)
   return $objResponse->getXML();
}
  1. 在你的腳本輸出任何信息之前,調(diào)用xajax用于接管請(qǐng)求:
$xajax->processRequests();
  1. 在頁(yè)面的 <head></head> 標(biāo)簽之間, 告訴xajax生成所必需的javascript:
<?php $xajax->printjavascript(); ?>
  1. 在程序中,從javascript事件或者函數(shù)調(diào)用前面注冊(cè)的函數(shù):
<div id="SomeElementId"></div>
<button onclick="xajax_myFunction(SomeArgument);">
  1. Include the xajax class library:
require_once("xajax.inc.php");
  1. Instantiate the xajax object:
$xajax = new xajax();
  1. Register the names of the PHP functions you want to be able to call through xajax:
$xajax->registerFunction("myFunction");
  1. Write the PHP functions you have registered and use the xajaxResponse object to return XML commands from them:
  2. function myFunction($arg)
  3. {
  4.   // do some stuff based on $arg like query data from a database and
  5.   // put it into a variable like $newContent
  6.   // Instantiate the xajaxResponse object
  7.   $objResponse = new xajaxResponse();
  8.   // add a command to the response to assign the innerHTML attribute of
  9.   // the element with id="SomeElementId" to whatever the new content is
  10.   $objResponse->addAssign("SomeElementId","innerHTML", $newContent);
  11.   //return the XML response generated by the xajaxResponse object
  12.   return $objResponse->getXML();
}
  1. Before your script sends any output, have xajax handle any requests:
$xajax->processRequests();
  1. Between your <head></head> tags, tell xajax to generate the necessary javascript:
<?php $xajax->printjavascript(); ?>
  1. Call the function from a javascript event or function in your application:
  2. <div id="SomeElementId"></div>
<button onclick="xajax_myFunction(SomeArgument);">
 
就這么簡(jiǎn)單. xajax 會(huì)處理其他所有的事情. 你所要做的主要工作就是編寫(xiě)PHP函數(shù),然后從函數(shù)之中返回xajax的XML響應(yīng)。而后者通過(guò)xajaxResponse類(lèi)可以非常簡(jiǎn)單的生成.
That's it. xajax takes care of most everything else. Your biggest task is writing the PHP functions and returning xajax XML responses from them-- which is made extremely easy by the xajaxResponse class.
 
如何異步更新內(nèi)容?
Xajax最富有特色的功能或許就是xajaxResponse類(lèi). 其他的Ajax庫(kù)需要你自己編寫(xiě)javascript的回調(diào)句柄去處理一個(gè)異步請(qǐng)求返回的數(shù)據(jù)并更新內(nèi)容. xajax, 從另外一個(gè)角度來(lái)說(shuō), 允許你使用PHP簡(jiǎn)單的控制內(nèi)容. xajaxResponse 讓你在PHP函數(shù)之中創(chuàng)建XML指令返回給你的程序. XML將被xajax的消息分析器解析,指令將告訴xajax如何更新程序的內(nèi)容和狀態(tài). xajaxResponse類(lèi)目前提供了以下指令:
How do I update my content asynchronously?
Perhaps the most unique feature of xajax is the xajaxResponse class. Other Ajax libraries require you to write your own callback handlers in javascript to process the data returned from an asynchronous request and to update the content. xajax, on the other hand, allows you to easily control your content from PHP. The xajaxResponse class allows you to create XML instructions to return to your application from your PHP functions. The XML is parsed by xajax message pump and the instructions tell xajax how to update the content and state of your application. The xajaxResponse class currently offers the following commands:
  • addAssign($sTargetId,$sAttribute,$sData)
    給命名為$sTargetId的元素的$sAttribute屬性賦值$sData
$objResponse->addAssign("contentDiv","innerHTML","Some Text");
$objResponse->addAssign("checkBox1","checked","true");
  • addAssign($sTargetId,$sAttribute,$sData)
    Assigns the $sAttribute of the element identified by $sTargetId to $sData
$objResponse->addAssign("contentDiv","innerHTML","Some Text");
$objResponse->addAssign("checkBox1","checked","true");
  • addAppend($sTargetId,$sAttribute,$sData)
    給命名為$sTargetId的元素的$sAttribute屬性追加值$sData
$objResponse->addAppend("contentDiv","innerHTML","Some Text");
  • addAppend($sTargetId,$sAttribute,$sData)
    Appends $sData to the $sAttribute of the element identified by $sTargetId
$objResponse->addAppend("contentDiv","innerHTML","Some Text");
  • addPrepend($sTargetId,$sAttribute,$sData)
    預(yù)備給命名為$sTargetId的元素的$sAttribute屬性賦值$sData
$objResponse->addPrepend("contentDiv","innerHTML","Some Text");
  • addPrepend($sTargetId,$sAttribute,$sData)
    Prepends $sData to the $sAttribute of the element identified by $sTargetId
$objResponse->addPrepend("contentDiv","innerHTML","Some Text");
  • addReplace($sTargetId,$sAttribute,$sSearch,$sData)
    替換命名為$sTargetId的元素的$sAttribute屬性的值之中的$sSearch為$sData
$objResponse->addReplace("contentDiv","innerHTML","text","<strong>text</strong>");
  • addReplace($sTargetId,$sAttribute,$sSearch,$sData)
    replaces all instances of $sSearch with $sData in the $sAttribute of the element identified by $sTargetId
$objResponse->addReplace("contentDiv","innerHTML","text","<strong>text</strong>");
  • addClear($sTargetId,$sAttribute)
    清空命名為$sTargetId的元素的$sAttribute屬性的值
$objResponse->addClear("Input1","value");
  • addClear($sTargetId,$sAttribute)
    Clears the $sAttribute of the element identified by $sTargetId
$objResponse->addClear("Input1","value");
  • addCreate($sParentId, $sTagname, $sId, $sType)
    在已經(jīng)存在的命名為$sParentId的元素下添加一個(gè)名叫$sTagName的子元素,并且把他的id賦值為$sId,可選的類(lèi)型賦值為 $sType.
$objResponse->addCreate("form1","input", "pass", "password");
  • addCreate($sParentId, $sTagname, $sId, $sType)
    Adds a new $sTagName child element to an existing element identified by $sParentId, and assigns it the id $sId and the optional type $sType.
$objResponse->addCreate("form1","input", "pass", "password");
  • addRemove($sElementId)
    從你的程序之中移除命名為$sElementId的元素
$objResponse->addRemove("div1");
  • addRemove($sElementId)
    Removes the element identified by $sElementId from your application
$objResponse->addRemove("div1");
  • addAlert($sMsg)
    顯示一個(gè)內(nèi)容為 $sMsg 的警告框(javascript的Alert)
$objResponse->addAlert("This is some text");
  • addAlert($sMsg)
    Display an alert box with $sMsg
$objResponse->addAlert("This is some text");
  • addScript($sJS)
    執(zhí)行javascript代碼 $sJS (演示代碼原文有誤)
$objResponse->addScript("var txt = prompt('get some text');");
  • addScript($sJS)
    Execute the javascript code $sJS
$objResponse->addAlert("var txt = prompt('get some text');");
 
一個(gè)獨(dú)立的XML響應(yīng)可能包含多個(gè)指令, 他們將按照加入響應(yīng)的順序執(zhí)行. 讓我們用一個(gè)用戶在你的程序之中點(diǎn)擊按鈕為例來(lái)進(jìn)行說(shuō)明. onclick事件調(diào)用PHP函數(shù)對(duì)應(yīng)的javascript封裝.這個(gè)封裝通過(guò)XMLHttpRequest發(fā)送異步請(qǐng)求到服務(wù)器給xajax調(diào)用PHP函數(shù). PHP函數(shù)做了一次數(shù)據(jù)庫(kù)查詢, 處理了一些數(shù)據(jù), 或者序列化. 然后你使用xajaxResponse類(lèi)生成包含多個(gè)指令的xajax的XML響應(yīng) ,并回送給xajax的消息分析器執(zhí)行:
A single XML response may contain multiple commands, which will executed in the order they were added to the response. For example, let's say that a user clicks on a button in your application. The onclick event calls the javascript wrapper for a PHP function. That wrapper sends an asynchronous request to the server through XMLHttpRequest where xajax calls the PHP function. The PHP function does a database lookup, some data manipulation, or serialization. You use the xajaxResponse class to generate an xajax XML response containing multiple commands to send back to the xajax message pump to be executed:
    $objResponse = new xajaxResponse();
    $objResponse.addAssign("myInput1","value",$DataFromDatabase);
    $objResponse.addAssign("myInput1","style.color","red");
    $objResponse.addAppend("myDiv1","innerHTML",$DataFromDatabase2);
    $objResponse.addPrepend("myDiv2","innerHTML",$DataFromDatabase3);
    $objResponse.addReplace("myDiv3","innerHTML","xajax","<strong>xajax</strong>");
    $objResponse.addScript("var x = prompt("Enter Your Name");");
           
    return $objResponse->getXML();
 
$objResponse = new xajaxResponse();
    $objResponse.addAssign("myInput1","value",$DataFromDatabase);
$objResponse.addAssign("myInput1","style.color","red");
$objResponse.addAppend("myDiv1","innerHTML",$DataFromDatabase2);
$objResponse.addPrepend("myDiv2","innerHTML",$DataFromDatabase3);
$objResponse.addReplace("myDiv3","innerHTML","xajax","<strong>xajax</strong>");
$objResponse.addScript("var x = prompt("Enter Your Name");");
return $objResponse->getXML();
xajax消息分析器將會(huì)解析XML消息,并執(zhí)行以下工作:
  1. id為myInput1的元素的值將被賦值為 $DataFromDatabase的數(shù)據(jù).
  2. id為myInput1的元素的顏色將會(huì)變?yōu)閞ed.
  3. $DataFromDatabase2的數(shù)據(jù)會(huì)被追加到id為myDiv1的元素innerHTML之中.
  4. $DataFromDatabase3的數(shù)據(jù)會(huì)被預(yù)先賦值給id為myDiv2的元素innerHTML之中.
  5. id為myDiv3的元素的innerHTML 之中所有的"xajax"將被替換為"<strong>xajax</strong>"; 使得所有的單詞 xajax 顯示加粗.
  6. 一個(gè)提示框?qū)?huì)顯示,用來(lái)詢問(wèn)用戶姓名,從提示框返回的值會(huì)被命名為x的javascript變量接收.
The xajax message pump would parse the XML message and perform the following:
  1. The value of the element with id myInput1 would be assigned to the data in $DataFromDatabase.
  2. The color of the text in the element with id myInput1 would be changed to red.
  3. The data in $DataFromDatabase2 would be appended to the innerHTML of the element with id myDiv1.
  4. The data in $DataFromDatabase3 would be prepended to the innerHTML of the element with id myDiv2.
  5. All occurrences of "xajax" in the innerHTML of the element with id myDiv3 would be replaced with "<strong>xajax</strong>"; making all of the instances of the word xajax appear bold.
  6. a prompt would be displayed asking for the user's name and the value returned from the prompt would be placed into a javascript variable named x.
所有這些都由構(gòu)成的PHP函數(shù)在服務(wù)器端執(zhí)行并返回xajax的XML響應(yīng).
All of this is implemented on the server side in the PHP function by forming and returning an xajax XML response.
如何異步處理表單數(shù)據(jù)?
Xajax使得異步處理表單數(shù)句非常非常的簡(jiǎn)單. xajax.getFormValues()方法會(huì)自動(dòng)的從表單提取數(shù)據(jù),并作為一個(gè)參數(shù)提交給xajax注冊(cè)的PHP函數(shù).
xajax.getFormValues() 僅僅需要一個(gè)參數(shù), 可以是你需要處理得表單的id, 或者是一個(gè)實(shí)際的表單對(duì)象. 你也可以使用xajax.getFormValues作為一個(gè)參數(shù)給xajax 函數(shù), 例如:
xajax_processFormData(xajax.getFormValues('formId'));
xajax 會(huì)生成一個(gè)與表單數(shù)據(jù)對(duì)應(yīng)的請(qǐng)求字符串給xajax服務(wù)器解析,然后以一個(gè)與表單數(shù)據(jù)對(duì)應(yīng)的數(shù)組傳遞給PHP函數(shù),就想你提交表單使用PHP的$_GET數(shù)組那么簡(jiǎn)單.
Xajax可以處理類(lèi)似普通多維數(shù)組或者聯(lián)合數(shù)組(哈希數(shù)組)等形式的復(fù)雜輸入名字. 例如, 如果一個(gè)表單有三個(gè)多選框(checkboxes)并且都命名為 "checkbox[]", 但是值分別為 "check1", "check2", 和 "check3", 然后使用 xajax.getFormValues 函數(shù)作為參數(shù)傳遞給xajax 函數(shù), 則 PHP 函數(shù)會(huì)接受到一個(gè)如下的數(shù)組:
array (
  'checkbox' =>
  array (
    0 => 'check1',
    1 => 'check2',
    2 => 'check3',
  ),
)
作為函數(shù)參數(shù)的數(shù)組的結(jié)構(gòu)與傳統(tǒng)意義上提交表單之后的$_GET數(shù)組的結(jié)構(gòu)相同. 你可以訪問(wèn)數(shù)組之中的checkbox 的數(shù)據(jù): $aFormData['checkbox'][0]
How do I process form data asynchronously?
xajax makes processing form data asynchronously extremely easy. The xajax.getFormValues() method can be used to automatically extract the data from a form and pass it as a parameter to a PHP function you have registered with xajax.
xajax.getFormValues() takes one argument, which can be either the id of the form you want to process, or the actual form object. You use xajax.getFormValues as a parameter to your xajax function, like this:
xajax_processFormData(xajax.getFormValues('formId'));
xajax generates a query string representing the form data which is parsed by the xajax server and passed to your PHP function as an array representing the form data, just as if you had submitted the form and used the PHP $_GET array.
xajax will even handle complex input names to generate multidimensional and associative arrays. For instance, if you have a form with three checkboxes and you give them all the name "checkbox[]", but different values like "check1", "check2", and "check3", and you use the xajax.getFormValues function as a parameter to your xajax function, the PHP function will receive and array that looks like this:
array (
  'checkbox' =>
  array (
    0 => 'check1',
    1 => 'check2',
    2 => 'check3',
  ),
)
The array argument to your function mirrors the structure that the $_GET array would have if you were to submit the form traditionally. You can then access the checkbox data in the array like this:
$aFormData['checkbox'][0]
如何給xajax增加定制功能?
Xajax可以使用各種服加的用戶定制功能進(jìn)行擴(kuò)展. 正因?yàn)閤ajax是完全面向?qū)ο蟮模⑶铱梢允褂脁ajaxResponse的addScript()方法,所以他具有無(wú)限擴(kuò)展的可能. 你可以創(chuàng)建你自己的xajax響應(yīng)類(lèi),來(lái)繼承xajaxResponse 類(lèi)以及它的方法,并加上你自己定制的響應(yīng). 讓我們用一個(gè)定制的增加選擇組合框(select combo boxes)選項(xiàng)的響應(yīng)指令的例子來(lái)說(shuō)明. 你可以象下面這樣擴(kuò)展xajaxResponse 類(lèi):
class myXajaxResponse extends xajaxResponse
  function addAddOption($sSelectId, $sOptionText, $sOptionValue) 
  { 
    $sScript  = "var objOption = new Option('".$sOptionText."','".$sOptionValue."');";
    $sScript .= "document.getElementById('".$sSelectId."').options.add(objOption);";
    $this->addScript($sScript);
  }
}
現(xiàn)在, 取代xajaxResponse 對(duì)象的初始化, 把你自己的 myXajaxResponse 對(duì)象的初始化定義到你的 xajax PHP 函數(shù)之中:
$objResponse = new myXajaxResponse();
$objResponse->addAssign("div1", "innerHTML", "Some Text"); 
$objResponse->addAddOption("select1","New Option","13"); 
 
return $objResponse->getXML();
被調(diào)用時(shí),這個(gè)方法將會(huì)發(fā)送需要的javascript到頁(yè)面并執(zhí)行. 當(dāng)然你也有另外一種做法Alternatively, 你可以在你的程序之中創(chuàng)建一個(gè)如下的javascript函數(shù):
<script type="text/javascript">
function addOption(selectId,txt,val)
{
        var objOption = new Option(txt,val);
        document.getElementById(selectId).options.add(objOption);
}
</script>
并且使用addScript() 調(diào)用這個(gè)方法:
$objResponse->addScript("addOption('select1','New Option','13');");
How do I add custom functionality to xajax?
xajax can be extended with all kinds of additional custom functionality. The extendability of xajax is made possible because it is object oriented, and by the addScript() method of the xajaxResponse class. You can create your own xajax response class that extends the xajaxResponse class and has all of the normal xajaxResponse methods, plus your own custom responses. For instance, let's say that you wanted to add a custom response command to add options to select combo boxes. You could extend the xajaxResponse class like this:
class myXajaxResponse extends xajaxResponse
  function addAddOption($sSelectId, $sOptionText, $sOptionValue) 
  {  
    $sScript  = "var objOption = new Option('".$sOptionText."','".$sOptionValue."');";
    $sScript .= "document.getElementById('".$sSelectId."').options.add(objOption);";
    $this->addScript($sScript);
  }
}
Now, instead of instantiating an xajaxResponse object, you instantiate and use your myXajaxResponse object in your xajax PHP functions:
$objResponse = new myXajaxResponse();
$objResponse->addAssign("div1", "innerHTML", "Some Text"); 
$objResponse->addAddOption("select1","New Option","13"); 
 
return $objResponse->getXML();
This method would send the necessary javascript to the page when it was called and execute it. Alternatively, you could create a javascript function in your application:
<script type="text/javascript">
function addOption(selectId,txt,val)
{
        var objOption = new Option(txt,val);
        document.getElementById(selectId).options.add(objOption);
}
</script>
and call it with the addScript() method:
$objResponse->addScript("addOption('select1','New Option','13');");
我能在私有或者收費(fèi)產(chǎn)品之中使用xajax嗎?
簡(jiǎn)而言之: 能,只要你愿意.
xajax PHP 類(lèi)庫(kù)的發(fā)布遵循 GNU Lesser General Public License (LGPL).
May I use xajax in a proprietary product and charge for it?
In short: Yes, you may.
The xajax PHP class library is released under the GNU Lesser General Public License (LGPL).
 
簡(jiǎn)體中文手冊(cè)版權(quán)所有 © 2005 HonestQiao(喬楚)
Copyright © 2005 J. Max Wilson
上一篇:AJAX的七宗罪

下一篇:如何成為AJAX高手

發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 欧美成人一二三区 | 日韩一级片一区二区三区 | 国产成人综合在线视频 | 麻豆91精品91久久久 | 日韩黄色片免费看 | 久久久久久久爱 | 日韩视频区 | 色妞视频男女视频 | 成人毛片100部免费观看 | 一级黄色淫片 | 香蕉国产9 | 日韩精品hd | 欧美一级黄 | 综合网天天色 | 91一区二区在线观看 | 成人三级电影网址 | 一区二区免费看 | 极色品影院 | 羞羞视频免费视频欧美 | 午夜爱爱福利 | 99riav国产在线观看 | 久久骚 | 成人在线视频免费观看 | av噜噜在线| 国产一国产精品一级毛片 | 粉嫩蜜桃麻豆免费大片 | 香蕉久久久 | 亚洲一区二区三区视频 | 久久久久成人免费 | 国产一级在线观看视频 | 久久蜜桃香蕉精品一区二区三区 | 中文字幕综合在线观看 | 久草导航 | 嫩呦国产一区二区三区av | 黄色av网站免费 | 91懂色| 欧美1区2区 | 国产三级国产精品国产普男人 | 色婷婷av一区二区三区久久 | 国产va在线观看 | 韩毛片 |