Home > Backend Development > PHP Tutorial > Introduction and trial introduction to php's ajax framework xajax_PHP tutorial

Introduction and trial introduction to php's ajax framework xajax_PHP tutorial

WBOY
Release: 2016-07-21 15:32:50
Original
786 people have browsed it

1. Comparison between xajax and other ajax frameworks
The function of xajax is very simple, but very flexible! ~It is not like some other large frameworks. Its functions are indeed powerful, but its execution speed cannot be complimented. . Although it has many functions, it is not flexible enough. There are so many APIs that it’s like learning a new language.
2. Introduction to xajax functions
The functions of xajax are relatively simple, but because of its simplicity, it is flexible. At the same time, this also requires users to have a certain understanding of javascrīpt/vbs client scripts. Because its function is relatively lively. It can be said that nothing can be done by simply using xajax, but everything can be done with js/vbs.
xajax mainly uses the xajaxResponse class, which provides some methods, for example:
1. addAlert($sMsg)
pops up a warning
2. addscrīpt($sJS)
execute a certain Section js
3. $objResponse->addAssign("","","")
Add a value to an element in the page, or modify its attributes
and so on. . . .

So xajax is not dead, it cannot make XXX XXX functions, but it can flexibly control the js/vbs of the client to achieve the effect we want to achieve.

3. Xajax installation configuration
No special installation and configuration is required. Just download the file package and extract it to the website directory
Download address:
http: //www.xajaxproject.org/

4. Use xajax for member registration and login
1. The database
uses mysql5.0, 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 (with instructions inside)

Copy code 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 a xajax object for singup.php
$xajax->registerFunction("processForm");
//Use the processForm function in singup.php
? >



Untitled Document
printJavascrīpt('inc/'); ?>
function submitSignup()
{
xajax.$('submitButton').disabled=true;
xajax.$('submitButton').value="http://blogbeta.blueidea .com/wait...";
//Modify the attribute with id as submitButton
xajax_processForm(xajax.getFormValues("signupForm"));
//Here xajax_ is followed by which function to use. Here is processForm, followed by a collection of signupForm form items
return false;
}










tr>





< /tr>










Username:
*


*
Password:
*
Email:

* can be used to retrieve password









After clicking submit, execute the processForm function in singup.php

3. inc/singup.php
Copy the code The code is as follows:

define ('XAJAX_DEFAULT_CHAR_ENCODING', 'gb2312' );
//Note here, gb2312 must be set, otherwise Chinese will be garbled
require_once(" xajax.inc.php");
require_once("function.php");
$xajax = new xajax();
$xajax->registerFunction("processForm");
/ /Same as 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 be filtered
$ArrFiltrate=array("'",";","union");

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

if (trim($usr) == "")
{
$errmsg.="Please enter username!n";
}
if (trim($pwd) == "")
{
$errmsg.="Please enter password!n";
}
if ($pwd != $aFormValues ['pwd2'])
{
$errmsg.="The passwords entered twice 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.="Username 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);
//Pop up error message
$objResponse->addAssign("submitButton","value","continue");
//Modify the value of submitButton to continue
$objResponse->addAssign("submitButton","disabled ",false);
//Modify the properties of submitButton
}

return $objResponse;
}


$xajax->processRequests ();
?>

The validity of the information is judged in this file, including: whether the user name has been registered, whether there are illegal characters in the information, whether the email address is correct, Check whether the passwords entered twice are consistent. If there is no error, enter it into the database and
$objResponse->addAssign("formDiv", "innerHTML",$sForm);
Reinsert the code in formDiv. The content is $sForm
$sForm = "Registration successful
Username:".$usr."
email:".$email."";

If there is an error message Then
$objResponse->addAlert($errmsg);
//The error message pops up
$objResponse->addAssign("submitButton","value","continue");
$ objResponse->addAssign("submitButton","disabled",false);
//Modify the attributes of submitButton

3. login.php login file
Copy code The code is as follows:

require_once("inc/xajax.inc.php");
$xajax = new xajax("inc/login.php");
$xajax->registerFunction("processForm");
?>



无标题文档
printJavascrīpt('inc/'); ?>

function submitSignup()
{
xajax.$('submitButton').disabled=true;
xajax.$('submitButton').value="http://blogbeta.blueidea.com/wait...";
xajax_processForm(xajax.getFormValues("signupForm"));
return false;
}




用 户 登 陆



















用户名:
*
密码:
*








4、inc/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="";
//要过滤的非法字符
$ArrFiltrate=array("'",";","union");

foreach($aFormValues as $key=>$value){
if (FunStringExist($value,$ArrFiltrate)){
$objResponse->addAlert("输入的信息含有非法字符"' ; union!"");
$objResponse->addAssign("submitButton","value","继续");
$objResponse->addAssign("submitButton","disabled",false);
return $objResponse;
}
}

if (trim($usr) == "")
{
$errmsg.="请输入用户名!n";
}
if (trim($pwd) == "")
{
$errmsg.="请输入密码!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.="用户名不存在,或密码错误!n";
}
if ($errmsg=="")
{
$sForm = "登陆成功";
$objResponse->addAssign("formDiv","innerHTML",$sForm);
}
else
{
$objResponse->addAlert($errmsg);
$objResponse->addAssign("submitButton","value","继续");
$objResponse->addAssign("submitButton","disabled",false);
}

return $objResponse;
}


$xajax->processRequests();
?>

登陆于注册原理差不多,就不废话了:)

另外下面是两个用到的文件代码 conn.php function.php
conn.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

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

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/322770.htmlTechArticle1. Comparison between xajax and other ajax frameworks The xajax function is very simple, but very flexible! ~It is not like some other large frameworks. Its functions are indeed powerful, but its execution speed cannot be complimented. . Although there are many functions,...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template