PHP ajax framework xajax introduction and trial introduction

  • 2020-03-31 21:23:33
  • OfStack

One, xajax and other ajax framework comparison
Xajax is simple, but flexible! ~ it is not like some other big framework, the function is really powerful, but the execution speed is not flattering. Many features, but not flexible enough. With so many apis, it's like learning a new language.
Ii. Xajax function introduction
Xajax's functionality is simple, but it's flexible because of its simplicity. At the same time, this also requires the user to have a certain understanding of javascr pt/VBS client script. Because its function is relatively live. It can be said that simple use of xajax, nothing can be done, but with js/VBS and everything.
Xajax mainly USES the class xajaxResponse, which provides some methods, for example:
1, addAlert ($sMsg)
Pop-up warning
2, addscr and pt ($sJS)
Execute some segment of js
3, $objResponse - > AddAssign (" ", ""," ")
Attach a value to an element on the page, or modify its attributes
Wait...

So xajax is not dead, it can not do XXX XXX function, but it can flexibly control the client js/VBS, to achieve the effect we want to achieve.

Three, xajax installation configuration
No special installation or configuration is required, just download the package and unzip it to the site directory
Download address:
http://www.xajaxproject.org/

Four, use xajax to do membership registration and login
1. Database
Using mysql5.0, database name zl table name zl_user table structure
Auto_increment id int (11)
Zl_user varchar (50)
Zl_pwd varchar (50)
Email varchar (50)

http://blog.knowsky.com/

2. Reg.php registration file (with instructions)
 
<?php 
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 for singup.php
$xajax->registerFunction("processForm"); 
//Use the processForm function in singup.php
?> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> 
<link rel="stylesheet" href="http://blogbeta.blueidea.com/css/style.css" _fcksavedurl=""http://blogbeta.blueidea.com/css/style.css"" type="text/css"> 
<title> Headless document </title> 
<?php $xajax->printJavascr and pt('inc/'); ?> 
<scr and pt type="text/javascr and pt"> 
function submitSignup() 
{ 
xajax.$('submitButton').disabled=true; 
xajax.$('submitButton').value="http://blogbeta.blueidea.com/wait..."; 
//Change the property with the id submitButton
xajax_processForm(xajax.getFormValues("signupForm")); 
//So here's xajax_ followed by which function to use and here's processForm, followed by signupForm which is a collection of items in the form
return false; 
} 
</scr and pt> 
</head> 
<body><form id="signupForm" action="javascr and pt:void(null);"  not nSubmit="submitSignup();"> 
<div id="main"> 
<div id="m1"> with   households   note   Copies of the </div> 
<div id="formDiv"> 
<table width="100%" border="0" cellspacing="0" cellpadding="5"> 
<tr> 
<td align="right"> </td> 
<td> </td> 
</tr> 
<tr> 
<td width="31%" align="right"> User name: </td> 
<td width="69%"><input name="usr" type="text" id="usr" /> 
*</td> 
</tr> 
<tr> 
<td align="right"> Password: </td> 
<td><input name="pwd" type="password" id="pwd" /> 
*</td> 
</tr> 
<tr> 
<td align="right"> Password: </td> 
<td><input name="pwd2" type="password" id="pwd2" /> 
*</td> 
</tr> 
<tr> 
<td align="right">Email : </td> 
<td><input name="email" type="text" id="email" /> 
*  Can be used to retrieve passwords </td> 
</tr> 
<tr align="center"> 
<td colspan="2"><input type="submit" name="submitButton" value=" submit " class="button" /> 
<input type="reset" name="Submit2" value=" reset " class="button" /></td> 
</tr> 
</table> 
</div> 
</div> 
</form> 
</body> 
</html> 

Click submit to execute the processForm function in singup.php

3, inc/singup. PHP
 
<?php 
define ('XAJAX_DEFAULT_CHAR_ENCODING', 'gb2312' ); 
//Note here, you must set gb2312, or the Chinese will be garbled
require_once("xajax.inc.php"); 
require_once("function.php"); 
$xajax = new xajax(); 
$xajax->registerFunction("processForm"); 
//With 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=""; 
//Illegal characters to filter
$ArrFiltrate=array("'",";","union"); 

foreach($aFormValues as $key=>$value){ 
if (FunStringExist($value,$ArrFiltrate)){ 
$objResponse->addAlert(" The information entered contains illegal characters "' ; union!""); 
$objResponse->addAssign("submitButton","value"," Continue to "); 
$objResponse->addAssign("submitButton","disabled",false); 
return $objResponse; 
} 
} 

if (trim($usr) == "") 
{ 
$errmsg.=" Please enter a user name !n"; 
} 
if (trim($pwd) == "") 
{ 
$errmsg.=" Please enter your password !n"; 
} 
if ($pwd != $aFormValues['pwd2']) 
{ 
$errmsg.=" The passwords entered 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 username already exists !n"; 
} 
if ($errmsg=="") 
{ 
$sForm = " Registered successfully <br> The user name :".$usr."<br>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); 
//Error message pops up
$objResponse->addAssign("submitButton","value"," Continue to "); 
//Modify the value of the submitButton to continue
$objResponse->addAssign("submitButton","disabled",false); 
//Modify the property of the submitButton
} 

return $objResponse; 
} 


$xajax->processRequests(); 
?> 

This file determines 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, whether the passwords entered twice are the same, if there are no errors, entered into the database, and
$objResponse - > AddAssign (" formDiv ", "innerHTML," $sForm);
Reinsert the code in the formDiv with $sForm
$sForm = "registration successful < Br> User name: ". $usr. "< Br> Email: ". $email. "";

If there is an error message
$objResponse - > AddAlert ($errmsg);
// error message pops up
$objResponse - > AddAssign (" submitButton ", "value", "continue to");
$objResponse - > AddAssign (" submitButton ", "disabled", false);
// modify the property of submitButton

3. Login.php login file
 
<?php 
require_once("inc/xajax.inc.php"); 
$xajax = new xajax("inc/login.php"); 
$xajax->registerFunction("processForm"); 
?> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> 
<link rel="stylesheet" href="http://blogbeta.blueidea.com/css/style.css" _fcksavedurl=""http://blogbeta.blueidea.com/css/style.css"" type="text/css"> 
<title> Headless document </title> 
<?php $xajax->printJavascr and pt('inc/'); ?> 
<scr and pt type="text/javascr and pt"> 
function submitSignup() 
{ 
xajax.$('submitButton').disabled=true; 
xajax.$('submitButton').value="http://blogbeta.blueidea.com/wait..."; 
xajax_processForm(xajax.getFormValues("signupForm")); 
return false; 
} 
</scr and pt> 
</head> 
<body><form id="signupForm" action="javascr and pt:void(null);"  not nSubmit="submitSignup();"> 
<div id="main"> 
<div id="m1"> with   households   deng   lu </div> 
<div id="formDiv"> 
<table width="100%" border="0" cellspacing="0" cellpadding="5"> 
<tr> 
<td align="right"> </td> 
<td> </td> 
</tr> 
<tr> 
<td width="31%" align="right"> User name: </td> 
<td width="69%"><input name="usr" type="text" id="usr" /> 
*</td> 
</tr> 
<tr> 
<td align="right"> Password: </td> 
<td><input name="pwd" type="password" id="pwd" /> 
*</td> 
</tr> 

<tr align="center"> 
<td colspan="2"><input type="submit" name="submitButton" value=" submit " class="button" /> 
<input type="reset" name="Submit2" value=" reset " class="button" /></td> 
</tr> 
</table> 
</div> 
</div> 
</form> 
</body> 
</html> 

4. Processing files for inc/login.php login
 
<?php 
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=""; 
//Illegal characters to filter
$ArrFiltrate=array("'",";","union"); 

foreach($aFormValues as $key=>$value){ 
if (FunStringExist($value,$ArrFiltrate)){ 
$objResponse->addAlert(" The information entered contains illegal characters "' ; union!""); 
$objResponse->addAssign("submitButton","value"," Continue to "); 
$objResponse->addAssign("submitButton","disabled",false); 
return $objResponse; 
} 
} 

if (trim($usr) == "") 
{ 
$errmsg.=" Please enter a user name !n"; 
} 
if (trim($pwd) == "") 
{ 
$errmsg.=" Please enter your 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 username does not exist , Or password error !n"; 
} 
if ($errmsg=="") 
{ 
$sForm = " Log in successfully "; 
$objResponse->addAssign("formDiv","innerHTML",$sForm); 
} 
else 
{ 
$objResponse->addAlert($errmsg); 
$objResponse->addAssign("submitButton","value"," Continue to "); 
$objResponse->addAssign("submitButton","disabled",false); 
} 

return $objResponse; 
} 


$xajax->processRequests(); 
?> 

Login in the registration principle is about the same, no nonsense :)

In addition, the following are two file codes used for conn. PHP function.php
Conn. PHP
 
<?php 
$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 

<?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 there are values in the array
function FunStringExist($StrFiltrate,$ArrFiltrate){ 
foreach ($ArrFiltrate as $key=>$value){ 
if (eregi($value,$StrFiltrate)){ 
return true; 
} 
} 
return false; 
} 
?> 


Related articles: