snllll 发表于 2010-4-12 22:18:16

翻译了TinyAjax

本帖最后由 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">&nbsp;</div>
</body>
</html>

snllll 发表于 2010-4-16 00:02:23

HEX老大谬赞了~~感动中

suncel0628 发表于 2010-6-24 10:44:56

哪里下载?

mxmx 发表于 2010-12-17 23:15:58

Mark一下~~

lioncn 发表于 2011-5-7 16:04:08

good job!

liu_qingbo 发表于 2011-5-12 19:48:05

:L
链接失效了!!

trynews 发表于 2011-5-13 16:35:39

看起来像好东西

baiyuxiong 发表于 2011-10-21 09:31:02

这个东西跟直接用JQUERY写JS相比,有什么优势呢?

fssnoo 发表于 2011-10-27 09:02:19

baiyuxiong 发表于 2011-10-21 09:31 static/image/common/back.gif
这个东西跟直接用JQUERY写JS相比,有什么优势呢?

玩玩还不错。

真正要生产,还是js归js,php归php好。

muyeyifan 发表于 2012-1-11 14:01:38

remark下
页: [1]
查看完整版本: 翻译了TinyAjax