Xajax是PHP一個(gè)不用刷新或者跳到其他頁(yè)面,就能通過點(diǎn)擊組件等與后臺(tái)后臺(tái)數(shù)據(jù)庫(kù)交互的技術(shù)
Xajax是php的一個(gè)插件,要想使用Xajax就必須先到其官網(wǎng)中下載一個(gè)壓縮包,由于國(guó)外的網(wǎng)速慢,我也給大家上傳了一個(gè)(點(diǎn)擊打開鏈接: https://pan.baidu.com/s/1gfkY3mj 密碼: bcvu),大家選擇下載。
下載完xajax_0.5_minimal.zip把里面的東西放到你要開發(fā)的工程目錄里面,比如筆者的工程目錄是C:\PHPnow-1.5.6\htdocs\myphp\xajax
xajaxhello.php,xjaxreg.php,xajaxregsuc.php是筆者自行開發(fā)的頁(yè)面,放在這里是為了說明 文件夾xajax_core,xajax_js 文件copyright.inc.php 一定要放在工程目錄,不要試圖再建一個(gè)文件夾把 文件夾xajax_core,xajax_js 文件copyright.inc.php 放在里面,這樣做理論是沒問題的,但在下面的操作過程中出錯(cuò)。
比如如下的xajax helloworld代碼:
<?php include '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>
比如你新建一個(gè)文件夾xajax把文件夾xajax_core,xajax_js 文件copyright.inc.php 放在里面,即使你改變上面helloworld代碼中的第二行,把include 'xajax_core/xajax.inc.php'; 改成 include 'xajax/xajax_core/xajax.inc.php';
在實(shí)際運(yùn)行中也會(huì)報(bào)錯(cuò),彈出如下的對(duì)話框:
整個(gè)程序無(wú)法運(yùn)行!
因此,一定要把 文件夾xajax_core,xajax_js 文件copyright.inc.php 放在工程目錄之下,反正也就三個(gè)文件不多。
下面來(lái)解釋一下,上面的helloworld代碼,
<?php include 'xajax_core/xajax.inc.php'; //指定動(dòng)作 $xajax=new xajax(); //相當(dāng)于聲明一個(gè)xajax處理函數(shù)myfunction $xajax->registerFunction("myfunction"); function myfunction($text){ //指定動(dòng)作 $orps=new xajaxResponse(); //調(diào)用orps中的alert方法,彈出helloworld對(duì)話框 $orps->alert("helloworld!"); //調(diào)用orps中的assign方法,指定id為div的div的內(nèi)文本為傳過來(lái)的text參數(shù) $orps->assign("div","innerHTML",$text); //以下是指定動(dòng)作 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部分關(guān)鍵是這里,說明我要調(diào)用xajax函數(shù)myfunction,且參數(shù)為helloworld--> <button onclick="xajax_myfunction('hello world');">ok</button> </body> </html>
于是這個(gè)xajaxhello.php的運(yùn)行結(jié)果為:
首先載入頁(yè)面的時(shí)候僅有一個(gè)ok,然后一點(diǎn)擊ok,與xajax發(fā)生了交互,彈出helloworld對(duì)話框,然后,設(shè)置id為div的div的內(nèi)文本為helloworld!
再點(diǎn)一次重復(fù)這個(gè)動(dòng)作。
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持。