Xajax features are simple, but flexible !~ Unlike some other big frameworks, it has powerful functions, but the execution speed is not flattering .. Although there are many functions, they are not flexible enough. With many APIs, learning is like learning a new language.
I. Comparison between xajax and other ajax frameworks
Xajax features are simple, but flexible !~ Unlike some other big frameworks, it has powerful functions, but the execution speed is not flattering .. Although there are many functions, they are not flexible enough. With many APIs, learning is like learning a new language.
II. Introduction to xajax functions
Xajax features are relatively simple, but it is flexible because it is simple. At the same time, this also requires the user to have a certain understanding of the ipvcr platinum pt/vbs client script. Because its functions are relatively active. It can be said that xajax alone can be used, but nothing can be done with js/vbs.
Xajax mainly uses the xajaxResponse class, which provides some methods, for example:
1. addAlert ($ sMsg)
Pop-up warning
2. addscr platinum pt ($ sJS)
Execute a js segment
3. $ objResponse-> addAssign ("","","")
Attaches a value to an element on the page or modifies its attributes.
And so on ....
Therefore, xajax is not dead. it cannot provide the XXX function, but it can flexibly control the js/vbs of the client to achieve the desired effect.
III. xajax installation and configuration
No special installation or configuration is required. you only need to download the package and decompress it to the website directory.
:
Http://www.xajaxproject.org/
4. use xajax for member registration and login
1. Database
Use mysql5.0 and database name zl table name zl_user table structure
Id int (11) auto_increment
Zl_user varchar (50)
Zl_pwd varchar (50)
Email varchar (50)
Http://blog.knowsky.com/
2. reg. php registration File (for instructions)
The code is as follows:
Require_once ("inc/xajax. inc. php ");
// To use xajax, you must first introduce xajax. inc. php
$ Xajax = new xajax ("inc/signup. php ");
// Create an xajax object named singup. php
$ Xajax-> registerFunction ("processForm ");
// Use the processForm function in singup. php
?>
Untitled Document
Printmediacr partition pt ('Inc/');?>
Function submitSignup ()
{
Xajax. $ ('submitclick'). disabled = true;
Xajax. $ ('submitclick'). value = "http://blogbeta.blueidea.com/wait ...";
// Modify the attribute of id to submitButton
Xajax_processForm (xajax. getFormValues ("signupForm "));
// Here, xajax _ is followed by the function to be used. processForm is followed by the set of signupForm items.
Return false;
}
Click submit and execute the processForm function in singup. php.
3. inc/singup. php
The code is as follows:
Define ('xajax _ DEFAULT_CHAR_ENCODING ', 'gb2312 ');
// Note that gb2312 must be set here, otherwise Chinese characters will be garbled
Require_once ("xajax. inc. php ");
Require_once ("function. php ");
$ Xajax = new xajax ();
$ Xajax-> registerFunction ("processForm ");
// Same as the reg. php file
Function processForm ($ aFormValues)
{
$ ObjResponse = new xajaxResponse ();
Require_once ("conn. php ");
$ Usr = $ aFormValues ['usr'];
$ Email = $ aFormValues ['email '];
$ Pwd = $ aFormValues ['pwd'];
$ Pw = Md5 ($ pwd );
$ Errmsg = "";
// Invalid characters to be filtered
$ ArrFiltrate = array ("'", ";", "union ");
Foreach ($ aFormValues as $ key => $ value ){
If (FunStringExist ($ value, $ ArrFiltrate )){
$ ObjResponse-> addAlert ("The entered information contains invalid characters \" '; union! \"");
$ ObjResponse-> addAssign ("submitButton", "value", "continue ");
$ ObjResponse-> addAssign ("submitButton", "disabled", false );
Return $ objResponse;
}
}
If (trim ($ usr) = "")
{
$ Errmsg. = "enter the user name! \ N ";
}
If (trim ($ pwd) = "")
{
$ Errmsg. = "enter the password! \ N ";
}
If ($ pwd! = $ AFormValues ['pwd2 '])
{
$ Errmsg. = "The two passwords are inconsistent! \ N ";
}
If (! CheckEmailAddr ($ email ))
{
$ Errmsg. = "the email address is incorrect! \ N ";
}
$ SQL = "select * from zl_usr where zl_usr = '$ usr '";
$ Result = mysql_query ($ SQL, $ db );
If ($ myrow = mysql_fetch_array ($ result )){
$ Errmsg. = "the user name already exists! \ N ";
}
If ($ errmsg = "")
{
$ SForm = "registration successful
Username: ". $ usr ."
Email: ". $ email ."";
$ SQL = "insert into zl_usr (zl_usr, zl_pwd, email) values ('$ usr',' $ pw ',' $ email ')";
$ Result = mysql_query ($ SQL, $ db );
$ ObjResponse-> addAssign ("formDiv", "innerHTML", $ sForm );
}
Else
{
$ ObjResponse-> addAlert ($ errmsg );
// The error message is displayed.
$ ObjResponse-> addAssign ("submitButton", "value", "continue ");
// Modify the value of submitButton to continue
$ ObjResponse-> addAssign ("submitButton", "disabled", false );
// Modify the attributes of the submitButton.
}
Return $ objResponse;
}
$ Xajax-> processRequests ();
?>
This file checks the validity of the information, including: whether the user name has been registered, whether there are illegal characters in the information, whether the email address is correct, and whether the two passwords are consistent, if there is no error, enter it in the database and
$ ObjResponse-> addAssign ("formDiv", "innerHTML", $ sForm );
Re-insert the code in formDiv with the content of $ sForm
$ SForm = "registration successful
Username: ". $ usr ."
Email: ". $ email ."";
If an error message exists
$ ObjResponse-> addAlert ($ errmsg );
// The error message is displayed.
$ ObjResponse-> addAssign ("submitButton", "value", "continue ");
$ ObjResponse-> addAssign ("submitButton", "disabled", false );
// Modify the attributes of the submitButton.
3. login. php login file
The code is as follows:
Require_once ("inc/xajax. inc. php ");
$ Xajax = new xajax ("inc/login. php ");
$ Xajax-> registerFunction ("processForm ");
?>
Untitled Document
Printmediacr partition pt ('Inc/');?>
Function submitSignup ()
{
Xajax. $ ('submitclick'). disabled = true;
Xajax. $ ('submitclick'). value = "http://blogbeta.blueidea.com/wait ...";
Xajax_processForm (xajax. getFormValues ("signupForm "));
Return false;
}
4. processing files for inc/login. php login
The code is as follows:
Define ('xajax _ DEFAULT_CHAR_ENCODING ', 'gb2312 ');
Require_once ("xajax. inc. php ");
Require_once ("function. php ");
$ Xajax = new xajax ();
$ Xajax-> registerFunction ("processForm ");
Function processForm ($ aFormValues)
{
$ ObjResponse = new xajaxResponse ();
Require_once ("conn. php ");
$ Usr = $ aFormValues ['usr'];
$ Email = $ aFormValues ['email '];
$ Pwd = $ aFormValues ['pwd'];
$ Pw = Md5 ($ pwd );
$ Errmsg = "";
// Invalid characters to be filtered
$ ArrFiltrate = array ("'", ";", "union ");
Foreach ($ aFormValues as $ key => $ value ){
If (FunStringExist ($ value, $ ArrFiltrate )){
$ ObjResponse-> addAlert ("The entered information contains invalid characters \" '; union! \"");
$ ObjResponse-> addAssign ("submitButton", "value", "continue ");
$ ObjResponse-> addAssign ("submitButton", "disabled", false );
Return $ objResponse;
}
}
If (trim ($ usr) = "")
{
$ Errmsg. = "enter the user name! \ N ";
}
If (trim ($ pwd) = "")
{
$ Errmsg. = "enter the password! \ N ";
}
$ SQL = "select * from zl_usr where zl_usr = '$ usr' and zl_pwd =' $ pw '";
$ Result = mysql_query ($ SQL, $ db );
If (! $ Myrow = mysql_fetch_array ($ result )){
$ Errmsg. = "the user name does not exist or the password is incorrect! \ N ";
}
If ($ errmsg = "")
{
$ SForm = "login successful ";
$ ObjResponse-> addAssign ("formDiv", "innerHTML", $ sForm );
}
Else
{
$ ObjResponse-> addAlert ($ errmsg );
$ ObjResponse-> addAssign ("submitButton", "value", "continue ");
$ ObjResponse-> addAssign ("submitButton", "disabled", false );
}
Return $ objResponse;
}
$ Xajax-> processRequests ();
?>
Login to the registration process is similar, no nonsense :)
In addition, the following two file codes are used: conn. php function. php.
Conn. php
The code is as follows:
$ Database = "zl"; // MYSQL database name
$ Db = mysql_connect ("127.0.0.1", "root", "123456"); // MYSQL database username and password
Mysql_select_db ($ database, $ db );
?>
Function. php
Function CheckEmailAddr ($ C_mailaddr)
{
If (! Eregi ("^ [_ a-z0-9-] (. [_ a-z0-9-]) * @ [a-z0-9-] (. [a-z0-9-]) * $ ",
$ C_mailaddr ))
{
Return false;
}
Return true;
}
// Whether the value in the array exists
Function FunStringExist ($ StrFiltrate, $ ArrFiltrate ){
Foreach ($ ArrFiltrate as $ key => $ value ){
If (eregi ($ value, $ StrFiltrate )){
Return true;
}
}
Return false;
}
?>