|  | 
 
| 本帖最后由 snllll 于 2010-4-12 22:28 编辑 
 源地址:http://codeigniter.com/wiki/TinyAjax/
 自己需要,就顺手给贴过来了,谈不上翻译不翻译的,因为太简单了。需要的看下:
 
 TinyAjax is a small php5 library that allows you to easily add AJAX-functionality to existing pages and create new AJAX-enabled pages with just a few lines of code.
 TinyAjax是一个小巧的php5的函数库,它可以使你非常方便的用很少几行代码添加AJAX到已经已经存在的页面,并且创建一个AJAX交互的页面。
 * Put the include/TinyAjax.php and TinyAjaxBehavior.php into system/application/libraries/
 * Put the include/TinyAjax.js into the “top-level directory”/js directory
 * Put the following code into system/application/init/init_tinyajax.php
 将include/TinyAjax.php和TinyAjaxBehavior.php放到system/application/libraries/下
 将the include/TinyAjax.js放置在 "顶层目录"/js下——重要
 将以下代码拷贝到system/application/init/init_tinyajax.php保存
 
 <?php if(!defined('BASEPATH')) exit('No direct script access aellowed');
 
 if (!class_exists('TinyAjax'))
 {
 define('TINYAJAX_PATH', BASEPATH.'application/libraries/');
 require_once(TINYAJAX_PATH.'TinyAjax'.EXT);
 }
 
 $obj =& get_instance();
 $obj->tinyajax = new TinyAjax();
 $obj->tinyajax->setScriptPath('../../js');
 $obj->tinyajax->setRequestType('post');
 
 ?>
 
 ————————————————————————————
 应用教程:Example of use
 A simple multiplication example. Here is the Controller.
 一个简单的乘法运算的例子,这是控制器的代码:
 ————————————————————————————
 <?php
 class Ajax extends Controller {
 
 function Ajax()
 {
 parent::Controller();
 $this->load->library('tinyajax');
 }
 
 function ajax_multiply($x, $y)
 {
 return $x*$y;
 }
 
 function multiply()
 {
 $this->tinyajax->showLoading();
 $this->tinyajax->exportFunction("ajax_multiply", array("first_id", "second_id"), "#third_id", $this);
 
 $this->tinyajax->process();
 $this->load->view('ajax_multiply');
 }
 }
 ?>
 ————————————————————————————
 视图:
 And here is the ajax_multiply.php views file:
 ————————————————————————————
 <html>
 <head>
 <? $this->tinyajax->drawJavaScript(false,true); ?>
 </head>
 <body>
 Multiply乘法:<br>
 <input type="text" id="first_id" value="2"> *
 <input type="text" id="second_id" value="3"> =
 <input type="text" id="third_id" value="">
 <input type="button" value=" * ">
 </body>
 </html>
 ————————————————————————————
 Example with Behavior
 Add this code to the controller: 将这些代码将入到控制器中
 ————————————————————————————
 function ajax_multiplyb($x, $y)
 {
 $res = $x * $y;
 $res_text = "Multiplying $x and $y results in $res{正在计算的$x和$y的结果是$res}";
 
 $tab = new TinyAjaxBehavior();
 $tab->add(TabSetValue::getBehavior("third_id", $res));
 $tab->add(TabInnerHtml::getBehavior("result_div", $res_text));
 return $tab->getString();
 }
 
 function multiplyb()
 {
 $this->tinyajax->showLoading();
 $this->tinyajax->exportFunction("ajax_multiplyb", array("first_id", "second_id"), null, $this);
 
 $this->tinyajax->process();
 $this->load->view('ajax_multiplyb');
 }
 
 ————————————————————————————
 And the views file ajax_multiplyb.php look like this:
 ————————————————————————————
 <html>
 <head>
 <? $this->tinyajax->drawJavaScript(false,true); ?>
 </head>
 <body>
 Multiply:<br>
 <input type="text" id="first_id" value="2"> *
 <input type="text" id="second_id" value="3"> =
 <input type="text" id="third_id" value="">
 <input type="button" value=" * ">
 <br/>
 <div id="result_div"> </div>
 </body>
 </html>
 
 | 
 评分
查看全部评分
 |