Tutorial: Learn xajax in 10 Minutesの和訳(完了)

http://xajaxproject.org/docs/xajax-in-10-minutes.php からの訳です。ver0.5。
相変わらずレベルの低いへたくそな訳ですが。。。m(_ _)m

ググると翻訳されているページがありました。
しっかりと翻訳されているページでしたので、そちらを参照下さい。(同じ内容をコピペ&ほんのちょっと改変)
http://dev.xajaxproject.org/wiki/index.php?title=JP:%C3%A5%E2%80%A6%C2%A5%C3%A9%E2%80%93%E2%82%AC:10%C3%A5%CB%86%E2%80%A0%C3%A9%E2%80%93%E2%80%9C%C3%A3%C2%81%C2%A7%C3%A8%C2%A6%C5%A1%C3%A3%C2%81%CB%86%C3%A3%E2%80%9A%E2%80%B9xajax%C3%A5%E2%80%A6%C2%A5%C3%A9%E2%80%93%E2%82%AC%C3%A7%C2%AF%E2%80%A1&diff=prev&oldid=1697

何で通常ページからいけないのかは謎ですが。。。
不便なので、こちらでも似たような内容を自分用にもメモ。


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:

xajaxは、新しいプロジェクトでも、既存のWEBアプリケーションでも両方ともに極めて簡単に実装できるように作られています。7つの簡単なステップでほとんど誰でもPHPスクリプトにxajaxの能力を加えることが出来ます。


1. Include the xajax class library:
1. xajaxのクラスライブラリをIncludeします。

require_once("xajax_core/xajax.inc.php");


2. Instantiate the xajax object:
2. xajaxオブジェクトをを生成します。

$xajax = new xajax();


3. Register the names of the PHP functions you want to be able to call through xajax:
3. xajaxを通して、利用したいPHP関数名を先ほど作成したオブジェクトに登録します。

$xajax->registerFunction("myFunction");


4. Write the PHP functions you have registered and use the xajaxResponse object to return XML commands from them:
4. 登録したPHP関数を実装して、関数の中にxajaxResponseオブジェクトを使用してXMLレスポンスを作成する。

function myFunction($arg)
{
    // do some stuff based on $arg like query data from a database and
    // put it into a variable like $newContent
    // 何人かのスタッフはデータベースからクエリデータを$args引数に基づいて    
    // 結果を$newContents変数へ

   $newContent = "Value of \$arg: ".$arg;
    
    // Instantiate the xajaxResponse object
    // xajaxResponseオブジェクトを生成する
    $objResponse = new xajaxResponse();
    
    // add a command to the response to assign the innerHTML attribute of
    // the element with id="SomeElementId" to whatever the new content is
    // HTMLのタグ要素IDが持つ指定した属性に新しい値を設定する
    // 例: 要素ID--"SomeElementId"、属性--"innerHTML"、値--$newContent

  $objResponse->assign("SomeElementId","innerHTML", $newContent);
    
    //return the  xajaxResponse object
    // xajaxResponseオブジェクトを返す
    return $objResponse;
}


5. Before your script sends any output, have xajax handle any requests:
5. スクリプトが出力を送信する前に、xajaxにリクエストハンドルを持たしてください。

$xajax->processRequest();


6. Between your tags, tell xajax to generate the necessary JavaScript:
6. タグ間で、必要なJavaScriptを生成するようにxajaxに命じてください。

<?php $xajax->printJavascript(); ?>


7. Call the function from a JavaScript event or function in your application:
7. アプリケーションの中にJavaScriptイベントが発生時の処理関数を定義する:
7. JavaScriptのイベントまたは関数からアプリケーション内の関数が呼ばれます。

<div id="SomeElementId"></div>
<button onclick="xajax_myFunction('It worked!');"></pre>


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.
以上です。xajaxがほとんどの処理をしてくれるので、あなたの仕事がPHP関数の実装とXMLリスポンスを組み立てるだけです-- xajaxResponseクラスあるので手軽に作れますね。
xajaxはその他すべての面倒をみてくれます。最大の仕事はPHP関数を記述していて、xajax XMLレスポンスを返します−それはxajaxResponseクラスによってとても簡単にされます。??アヤシイ。。。


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 a number of useful commands, such as Assign, which sets the specified attribute of an element in your page; Append, which appends data to the end of the specified attribute of an element in your page; Prepend, which prepends data to the beginning of the specified attribute of an element in your page; Replace, which searches for and replaces data in the specified attribute of an element in your page; Script, which runs the supplied JavaScript code; and Alert, which shows an alert box with the supplied message text.
おそらくxajaxの一番ユニークな特性といえば、やはり xajaxResponseクラスです。ほかのAjaxライブラリでしたら、あなた独自にJavascriptで非同期リクエストとリスポンスデータを処理する関数を実装しなければならないですが、xajaxがPHPから簡単にコンテンツをコントロールすることができます。xajaxResponseクラスによって、あなたのPHP関数だけで、非同期通信XMLデータをつくることができます。XMLはxajaxメッセージポンプにより解析され、そして、Webアプリケーションのコンテンツと状態を更新する方法がxajaxにより実装されます。


A single XML response may contain multiple commands, which will be 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:
ひとつのXMLのリスポンスの中に複数なコマンドを含めることができます。これらのコマンドはリスポンスに書かれた順番で実行されます。たとえば、ユーザがあなたのWebページ上のボタンをクリックとします。ボタンのonclickイベントがPHP関数のJavascriptラッパー関数をトリガーします。このラッパー関数はXMLHttpRequestを通して非同期リクエストをサーバに送信します。 サーバ側はxajaxが該当PHP関数を呼び出します。このPHP関数はDBのルックアップやデータの操作を行います。あなたは、xajaxResponseクラスを使用して、複数の命令を含んでいるxajax XMLリスポンスをxajaxメッセージポンプへ送ります:

$objResponse = new xajaxResponse();
$objResponse->assign("myInput1","value",$DataFromDatabase);
$objResponse->assign("myInput1","style.color","red");
$objResponse->append("myDiv1","innerHTML",$DataFromDatabase2);
$objResponse->prepend("myDiv2","innerHTML",$DataFromDatabase3);
$objResponse->replace("myDiv3","innerHTML","xajax","<strong>xajax</strong>");
$objResponse->script("var x = prompt(\"Enter Your Name\");");
return $objResponse;


xajaxメッセージポンプはXMLメッセージをパースして、以下の動作が実行されます:


ID名myInput1の要素のvalueプロパティに$DataFromDatabaseをセットする
ID名myInput1の要素のcolorスタイルがredに換える
ID名myDiv1の要素のinnerHTMLプロパティに$DataFromDatabase2データを追加する
ID名myDiv2の要素のinnerHTMLプロパティのデータ先頭に$DataFromDatabase3を追加する
ID名myDiv3の要素のinnerHTMLプロパティにあるすべての"xajax"文字列を"xajax"に置き換え、"xajax"をboldにする
ユーザ名を聞かれるようなダイアログボックスをポップアップ、ユーザ名をx変数にセットするJavascriptを生成する
以上すべてはサーバサイドのPHP関数およびxajax XMLリスポンスの形で実装されています。


But wait, there's more!
まだまだありますよ!!
Continue on to » Processing Forms with xajax
xajaxでFormsを処理する。