PHP's AJAX framework Xajax primer and trial

Source: Internet
Author: User
Keywords PHP's AJAX framework Xajax primer and trial

Please enter text in textbox PHP's AJAX framework Xajax getting started with trial

A comparison of Xajax and other Ajax frameworks
Xajax function is very simple, but very flexible! ~ It's not like some other big frame, the function is really powerful, but the execution speed is not flattering. Features are many, but not flexible enough. The API is so much, it's like learning a new language.
Second, Xajax function introduction
The function of Xajax is relatively simple, but because it is simple, it is flexible. At the same time, this also requires the user to have a certain understanding of the Javascrīpt/vbs client script. Because its function is relatively alive. Can say pure use xajax, what also can't do out, but cooperate with js/vbs and what all do out.
Xajax mainly uses the Xajaxresponse class, which provides some methods, such as the following:
1, Addalert ($SMSG)
Pop-up warning
2, addscrīpt ($sJS)
Execute a section JS
3, $objResponse->addassign ("", "", "")
Attach a value to an element in a page, or modify its properties
Wait a minute....

So Xajax is not dead, it can't make xxx xxx function, but it can control the client's js/vbs flexibly, to accomplish the effect we want to achieve.

Three, Xajax installation configuration
No special installation and configuration required, just download the package and extract it to the site Directory
Download Address:
http://www.xajaxPRoject.org/

Third, use Xajax to do membership registration and Login
1. Database
Using MySQL5.0, database name ZL table name Zl_user table structure
ID int (one) auto_increment
Zl_user varchar (50)
Zl_pwd varchar (50)
Email varchar (50)

http://blog.cncms.com/

2. Reg.php Registration Document (with instructions)

Require_once ("inc/xajax.inc.php");
Using Xajax, you must first introduce the xajax.inc.php
$xajax = new Xajax ("inc/signup.php");
Create a Xajax object for the singup.php
$xajax->registerfunction ("ProcessForm");
Using the ProcessForm function in singup.php
?>



<title>Untitled Document</title>  
Printjavascrīpt (' inc/');?>

function Submitsignup ()
{
xajax.$ (' Submitbutton '). Disabled=true;
xajax.$ (' Submitbutton '). value= "Http://blogbeta.blueidea.com/wait ...";
To modify an attribute with ID Submitbutton
Xajax_processform (Xajax.getformvalues ("Signupform"));
Here's the xajax_ followed by which function to use here is ProcessForm, followed by a collection of Signupform's form items
return false;
}




Execute the ProcessForm function in singup.php after point commit

3, inc/singup.php

Define (' xajax_default_char_encoding ', ' gb2312 ');
Note Here, you must set gb2312, otherwise 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 on
$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");
$objResponse->addassign ("Submitbutton", "disabled", false);
return $objResponse;
}
}
 
if (Trim ($usr) = = "")
{
$errmsg. = "Please enter user name!\n";
}
if (Trim ($pwd) = = "")
{
$errmsg. = "Please enter the password!\n";
}
if ($pwd! = $aFormValues [' pwd2 '])
{
$errmsg. = "two times input password inconsistent!\n";
}
 
if (! CHECKEMAILADDR ($email))
{
$errmsg. = "Incorrect mail address!\n";
}
$sql = "SELECT * from zl_usr where zl_usr= ' $usr '";
$result =mysql_query ($sql, $db);
if ($myrow =mysql_fetch_array ($result)) {
$errmsg. = "User name already exists!\n";
}
if ($errmsg = = "")
{
$sForm = "Registration Successful
User name: ". $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 Submitbutton property of this button
}
 
return $objResponse;
}


$xajax->processrequests ();
?>

The validity of the information in this file, including: whether the user name has been registered, the information whether there are illegal characters, the correct e-mail address, two times the password is consistent, if there is no error, enter into the database, and
$objResponse->addassign ("Formdiv", "InnerHTML", $sForm);
Reinsert the code in Formdiv with the contents of $sform
$sForm = "Registration Successful
User name: ". $usr."
Email: ". $email.";

If there is an error message
$objResponse->addalert ($errmsg);
Pop-up error message
$objResponse->addassign ("Submitbutton", "value", "continue");
$objResponse->addassign ("Submitbutton", "disabled", false);
Modify the Submitbutton property of this button

3. login.php Landing File

Require_once ("inc/xajax.inc.php");
$xajax = new Xajax ("inc/login.php");
$xajax->registerfunction ("ProcessForm");
?>



Untitled Document 
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. Processing documents for inc/login.php landing

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 on
$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");
$objResponse->addassign ("Submitbutton", "disabled", false);
return $objResponse;
}
}
 
if (Trim ($usr) = = "")
{
$errmsg. = "Please enter user name!\n";
}
if (Trim ($pwd) = = "")
{
$errmsg. = "Please 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. = "User name does not exist, or password error!\n";
}
if ($errmsg = = "")
{
$sForm = "landing success";
$objResponse->addassign ("Formdiv", "InnerHTML", $sForm);
}
Else
{
$objResponse->addalert ($errmsg);
$objResponse->addassign ("Submitbutton", "value", "continue");
$objResponse->addassign ("Submitbutton", "disabled", false);
}
 
return $objResponse;
}


$xajax->processrequests ();
?>

Landing on the principle of registration is similar, no nonsense:)

In addition, below are two files used in the code conn.php function.php
conn.php

$database = "ZL";//mysql database name
$db = mysql_connect ("127.0.0.1", "root", "123456");//mysql database user name 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 values in the array exist
function Funstringexist ($StrFiltrate, $ArrFiltrate) {
foreach ($ArrFiltrate as $key = = $value) {
if (eregi ($value, $StrFiltrate)) {
return true;
}
}
return false;
}
?>

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.