GTAjax / 通用Ajax
( LastUpdated:
12/04/2006 08:48:27 )
?
http://www.wadelau.net/index2.htmlAuthor: Wade Lau, wadelau@ufqi.com, wadelau@hotmail.com
Summary / 概述
GTAjax is
General-Targeted Ajax.
Ajax stands for
Asynchronous
JavaScript
And
XML.
GTAjax is a kind of Ajax, and beyond the Ajax.
Maybe you have see and have used it in some coding experience. And also, you have not found any inefficent, actually, common Ajax has its own limits in many ways, It depends on the environment heavily.
Mostly, you code one Ajax which can not run in another place with differences in Browser,Operating System,Bankend programming components,etc...
In order to comply with the differences, people creates many kinds of Ajax, amd so do I, luckily enough, I found one generally-targeted way to comply with all the differences... , I call it GTAjax. Another reason for this name is GTAjax also refers to
GridTask Ajax, based on gridtask.com .
GTAjax 就是
通用(General-Targeted)Ajax的意思。是Ajax的一種. Ajax是異步Javascript和XML應用的合稱。 可能你已經見到和使用過Ajax的應用,并且還沒有發現它有什么不足。實際上,Ajax本身有很多限制,它對環境的依賴很強。
大多數情況是你在一處寫的Ajax無法在別的地方使用,它對瀏覽器,操作系統和后臺程序都有不同的限制和要求。
人們為了完成各樣環境下的Ajax應用,編寫不了不同的Ajax版本,我也一樣,幸運的是我找到一個可以通行應用于不同環境下的Ajax,我叫它GTAjax。 取這個名字的另外一個原因是,GTAjax 也代表 GridTask Ajax 的意思,因為GTAjax就產生在
gridtask.com 。
Feathers / 特征
GTAjax的特征表現在:
1. 具有Ajax的功用,可替代Ajax的工作
2. 其通用性表現在:
????a. 與操作系統無關,這應是javascript的本性
????b. 與瀏覽器無關,目前我們已經在MSIE,Mozilla firefox,Opera上測試通過
????c. 與Web服務器無關, 不依賴于Web服務器的特質去完成任務,可在流行的Apache,IIS等Web server運營的站點使用
????d. 與后臺腳本應用程序無關, 也即針對后臺服務器腳本asp,php,jsp,perl等無須做改動
3. 對Ajax的硬傷--文件上傳作了單獨的優化處理
4. 代碼精簡,僅有7k左右 , (帶表單驗證有12K)
5. 使用簡便,可調用操作,設置不同運行參數
6. 無需設置服務器端,這一點聽起來很荒謬
7. 表單驗證(v1.58+)
GTAjax's feathers include:
1. do what Ajax can do
2. its general feather as following:
???? a. no mater what OS , inherits from javascript
???? b. no matter what Browser, it has been tested pass in MSIE, firefox, Opera
???? c. no matter what web server, it can used in Apache, IIS, etc
???? d. no matter what backend programming language, it can be used with jsp, asp, php, perl,etc
3. for Ajax's shortcoming--file upload, it has been optimised to handle files upload correctly
4. small size, only about 7k , (with form validator up to 12k)
5. easy to use, with parameters to set for specified running
6. no action needed with server, which sounds unreasonable
7. form validator (v1.58+)
Usage / 用法
在您的網頁代碼中加入:[place the following code in your page]
.... <script type="text/javascript" src="GTAjax_.js"></script> ....? |
然后寫出自己的業務處理函數[then, write you own functions]:
....
function subMyForm(sFrm) { // before submiting... setGTAjax('returnname','Back'); // do settings 設置環境變量 var getTmpStr = GTAjax(sFrm); // main action 調用主函數處理并取結果 // after submited... }
GTAjax不但能遞交表單,也可處理url請求 [also,GTAjax could handle url request] function handleMyUrl(sUrl) { // before go to next url.... setGTAjax('targetarea','newdiv');// 設置將從服務器端取到的內容顯示到新區域 //setGTAjax('returndataonly',true); setGTAjax('iscache',false); // 設置是否處理緩存,更多設置見附后參考[with more settings in the following part] var getTmpStr = GTAjax(sUrl); // 主處理函數 // after get remote material... } ....? |
接著將這些動作綁定到對象去[then, bind the function to your target]:
....
<span id="formArea">(請將form放到一個對象中去,place form in a named object) <br/> <form name="myform" id="myform" action="thisform.do.php" method="post" onsubmit="return false;">(禁用默認遞交,disable the default submit, 1.69+不再做要求) <input type="text" id="userName" name="userName" value="Wade Lau"/><br/> .... <input type="submit" value="Submit" id="btn1" name="btn1" onClick="javascript:subMyForm(this.form.name);"/>(這里的參數是表單名,here give function the form's name)<br/> </form> </span> ...? |
ok,done.
現在,開始吧[now, it is time to go] .... Reference and Download / 參考和下載
@ GTAjax運行時配置參考[settings references]:
.... setGTAjax('subbtnval','Submit'); // 表單遞交按鈕顯示的字符,默認是Submit setGTAjax('maxuploadfiletime',3*60*1000); // 上傳文件等待回應的最大時間,默認是3分鐘 setGTAjax('targetarea','areaname'); // 遞交請求獲取數據后寫在當前頁面的何處,默認是遞交元素所在的區域 setGTAjax('returnname','Return'); // 表單遞交后,返回鏈接的顯示字符,默認是Return setGTAjax('returndataonly',false); // 是否僅僅取得返回數據(而不向目標區域寫入),默認是false setGTAjax('iscache',true); // 是否緩存從服務器取得的內容,默認是true setGTAjax('forceframe',false); // 是否強制使用iframe技術,即便沒有fileupload行為也不使用xmlhttp,在一些xmlhttp受限的地方可使用iframe代替 setGTAjax ('processbar',true); // 是否顯示處理中提示條, 默認是顯示 (1.89+, idea from ayg at founder dot com) setGTAjax ('backlink',true); // 是否在返回內容中追加返回鏈接,默認為是(1.89+ ) setGTAjax('forceframetag','fftag'); //告知服務器端,此次請求是普通請求,非xmlhttp,服務器端可據此fftag=1來判斷(1.91+) setGTAjax('chkform','userMail:email+:user mail should be an valid email address'); // 設定表單遞交驗證項(詳細見下表) .... |
GTAjax的表單驗證,其配置為:
setGTAjax('chkform','userMail:email+:user mail should be an valid email address');
其中'chkform' : tell GTAjax to validate form data.
'userMail: email+: user mail should be an valid email address'
'strFormFieldName:formValidateType: errorMessage'
GTAjax Form Validation Descriptors // GTAjax 表單驗證關鍵字描述
formValidateType | Explainations[partly from http://www.javascript-coder.com ] |
required req | The field should not be empty // 不能為空 |
maxlen=??? maxlength=??? | checks the length entered data to the maximum. For example, if the maximum size permitted is 25, give the validation descriptor as "maxlen=25" // 長度檢測,至多允可長度, 如欲限定在25字符內,則使用表達式, "maxlen=25", 在GTAjax中的完整表達為 setGTAjax('chkform','strField:maxlen=25:this field max length is 25.'); |
minlen=??? minlength=??? | checks the length of the entered string to the required minimum. example "minlen=5" //最小限定為 |
alphanumeric alnum | Check the data if it contains any other characters other than alphabetic or numeric characters //僅為字母和數字(不含符號等) |
num numeric | Check numeric data // 僅為數字 |
alpha alphabetic | Check alphabetic data. // 僅為字母 |
email | The field is an email field and verify the validity of the data. // 限為合法email地址 |
lt=??? lessthan=??? | Verify the data to be less than the value passed. Valid only for numeric fields. example: if the value should be less than 1000 give validation description as "lt=1000" // 其值不小于 |
gt=??? greaterthan=??? | Verify the data to be greater than the value passed. Valid only for numeric fields. example: if the value should be greater than 10 give validation description as "gt=10" // 其值不大于 |
regexp=??? | Check with a regular expression the value should match the regular expression. example: "regexp=^[A-Za-z]{1,20}$" allow up to 20 alphabetic characters. // 其值符合給定的正則表達式 |
dontselect=?? ?Deprecated | This validation descriptor is valid only for select input items (lists) Normally, the select list boxes will have one item saying 'Select One' or some thing like that. The user should select an option other than this option. If the index of this option is 0, the validation description should be "dontselect=0" // 這個是 http://www.javascript-coder.com 的標配, 其本身局限大,功能小,舍棄 |
notvalue=???
newlyadded | Verify the data to be any data other than the specified value // 是上面一個的的升級和擴容,是一個反向概括,如不能讓其值為空"notvalue=" , 不能選擇第一個選項"notvalue=1",用戶名一項的值不能等于初始值"notvalue=用戶名"... |
(anyofabove)+
newlyadded | the "+" means req, or required, not empty when added up to any type of validating above, e.g. "email+" which means the expected value is an email address, and the field also is required, not empty. // 在寫表單驗證時參考了很多目前流行的,這個就是精簡的結果,比如其中一項,即要符合email地址規范,又不能為空,則 "email+" , 其中一項只能是數字,且不能留空,則 "num+",... |
< 下載/Download
2006.10.12, GTAjax/通用Ajax-1.91 2006.09.22, GTAjax/通用Ajax-1.89 2006.07.25, GTAjax/通用Ajax-1.86 2006.07.07, GTAjax/通用Ajax-1.72 2006.05.23, GTAjax后端腳本之aspx 2006.05.23, GTAjax后端腳本之php 2006.03.22, GTAjax/通用Ajax-1.69 2006.03.15, GTAjax/通用Ajax-1.58, with form validator.2006.03.12, GTAjax/通用Ajax-1.36
2006.02.17, GTAjax/通用Ajax-1.28
Thanks and Declarations / 致謝與聲明
I wanna say THANKS :
to my home, they do more and spare me to have time code these. 感謝我的家人,他們更多的操勞才使我有時間寫這些.
to Google, without its motivation, I have no idea about Ajax, and without it, I hardly complete this code.感謝Google,因其而起而又得其力.
to dong_li98@hotmail.com, we do together an exciting action by submitting a form twice with javascript, which contributes mainly to this script. 感謝dong_li98@hotmail.com,我們一起制造了一個表單遞交兩次的嘗試,這個思想對本文影響很大.
to AjaxAnywhere[JSP based Ajax], to Prototype[javascript extend library], to W3C, to RFC, to DOM, to lots of people who works on js and share their scripts with us ... 還要感謝AjaxAnywhere[jsp 環境中的Ajax],Prototype[javascript的擴展庫], W3C, RFC, DOM 和其他許多在網上共享他們的js腳本的人...
NOTICE:
DO NOT USE THIS COMMERICALLY WITHOUT AUTHOR'S PAPER AUTHORIZATION.僅供個人免費使用,請勿復制用于商業獲利.
if needed, please contact with us at
mailto:wadelau@ufqi.com?subject=GTAjax 如有必要請聯絡
mailto:wadelau@ufqi.com?subject=GTAjax 獲取授權.