標籤:php xajax 資料庫 helloworld ajax
Xajax是PHP一個不用重新整理或者跳到其他頁面,就能通過點擊組件等與後台後台資料庫互動的技術
Xajax是PHP的一個外掛程式,
要想使用Xajax就必須先到其官網中下載一個壓縮包(點擊開啟連結),由於國外的網速慢,我也給大家上傳了一個(點擊開啟連結),大家自行選擇下載。
下載完xajax_0.5_minimal.zip把裡面的東西放到你要開發的工程目錄裡面,比如筆者的工程目錄是C:\PHPnow-1.5.6\htdocs\myphp\xajax
xajaxhello.php,xjaxreg.php,xajaxregsuc.php是筆者自行開發的頁面,
放在這裡是為了說明 檔案夾xajax_core,xajax_js 檔案copyright.inc.php 一定要放在工程目錄
不要試圖再建一個檔案夾把 檔案夾xajax_core,xajax_js 檔案copyright.inc.php 放在裡面,
這樣做理論是沒問題的,但在下面的操作過程中出錯。
比如如下的xajax helloworld代碼:
<?phpinclude 'xajax_core/xajax.inc.php';$xajax=new xajax();$xajax->registerFunction("myfunction");function myfunction($text){$orps=new xajaxResponse();$orps->alert("helloworld!");$orps->assign("div","innerHTML",$text);return $orps;}$xajax->processRequest();$xajax->printJavascript();?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>xajax</title></head><body><div id="div"></div><button onclick="xajax_myfunction('hello world');">ok</button></body></html>
比如你建立一個檔案夾xajax把檔案夾xajax_core,xajax_js 檔案copyright.inc.php 放在裡面,
即使你改變上面helloworld代碼中的第二行,把include ‘xajax_core/xajax.inc.php‘; 改成 include ‘xajax/xajax_core/xajax.inc.php‘;
在實際運行中也會報錯,彈出如下的對話方塊:
整個程式無法運行!
因此,一定要把 檔案夾xajax_core,xajax_js 檔案copyright.inc.php 放在工程目錄之下,反正也就三個檔案不多。
下面來解釋一下,上面的helloworld代碼,
<?phpinclude 'xajax_core/xajax.inc.php';//指定動作$xajax=new xajax();//相當於聲明一個xajax處理函數myfunction$xajax->registerFunction("myfunction");function myfunction($text){//指定動作$orps=new xajaxResponse();//調用orps中的alert方法,彈出helloworld對話方塊$orps->alert("helloworld!");//調用orps中的assign方法,指定id為div的div的內文本為傳過來的text參數$orps->assign("div","innerHTML",$text);//以下是指定動作return $orps;}$xajax->processRequest();$xajax->printJavascript();?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>xajax</title></head><body><div id="div"></div><!--html部分關鍵是這裡,說明我要調用xajax函數myfunction,且參數為helloworld--><button onclick="xajax_myfunction('hello world');">ok</button></body></html>於是這個xajaxhello.php的運行結果為:
首先載入頁面的時候僅有一個ok,然後一點擊ok,與xajax發生了互動,彈出helloworld對話方塊,然後,設定id為div的div的內文本為helloworld!
再點一次重複這個動作。
【php】Xajax Helloworld