Vernacular Ajax and Its BASICS (2)

Source: Internet
Author: User

Iv. common Ajax programming frameworks
Now that the above Ajax framework is ready to work, why are there so many frameworks?
With the complexity of the page, you may need to write a large number of JavaScript scripts to control the DOM objects in the page. The workload and complexity will greatly increase. Ajax programming frameworks generally use object-oriented methods to reasonably encapsulate some basic objects, behaviors, and their complexity, and build a set of class libraries with their own characteristics, it also takes into account the advantages of efficiency and scalability. During development, we can use less and clearer code to complete our work. It also gives programmers more time and energy to consider the business logic itself, rather than being entangled with a bunch of scripts.
The framework is related to background scripts. Through Background scripting, we can build browser-compatible Ajax applications without having to write a large number of JavaScript scripts.
For example, I used a popular PHP xajax framework to rewrite the front sample program:
<? PHP
Require_once ("../xajax. Inc. php ");

// Server processing functions
Function processform ($ aformvalues)
{
$ Objresponse = new xajaxresponse ();
$ Berror = false;

// Clear the error message
$ Objresponse-> addclear ("usernameinfo", "innerhtml ");

// Determine the account
If (TRIM ($ aformvalues ['username']) = "")
{
$ Objresponse-> addappend ("usernameinfo", "innerhtml", "Please input user name .");
$ Berror = true;
}
Else
{
If (TRIM ($ aformvalues ['username']) = "Thomas ")
$ Objresponse-> addappend ("usernameinfo", "innerhtml", "has been registed ");
Else
$ Objresponse-> addappend ("usernameinfo", "innerhtml", "has not been registed ");
$ Berror = false;
}

If (! $ Berror)
{
$ Sform. = "<div> account:". $ aformvalues ['username']. "</div>/N ";
}
Else
{
$ Objresponse-> addassign ("submitbutton", "value", "Submit ");
$ Objresponse-> addassign ("submitbutton", "disabled", false );
}

Return $ objresponse;
}

// Construct an object
$ Xajax = new xajax ();

// Register the processing function
$ Xajax-> registerfunction ("processform ");

// Take over the HTTP request
$ Xajax-> processrequests ();
?>

<! Doctype HTML public "-// W3C // dtd xhtml 1.0 transitional // en" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<HTML>
<Head>
<Meta http-equiv = "Content-Type" content = "text/html; charset = gb2312">
<? PHP
// Generate necessary Javascript
$ Xajax-> printjavascript ('../xajax /');
?>

<Title> xajax user registration </title>
<Style type = "text/CSS">
# Formwrapper {color: #111111; Background-color: RGB (200,200,200); width: 360px ;}
# Title {color: # ffffff; text-align: center; Background-color: #000000 ;}
# Formdiv {padding: 20px ;}
. Submitdiv {margin-top: 10px; text-align: center ;}
. Errorspan {color: red ;}
</Style>

<SCRIPT type = "text/JavaScript">
<! -- // Submit a form
Function submitsignup ()
{
Xajax. $ ('submitclick'). Disabled = true;
Xajax. $ ('submitclick'). value = "verifying ...";
Xajax_processform (xajax. getformvalues ("signupform "));
Return false;
}
// -->
</SCRIPT>

</Head>

<Body>

<Form ID = "signupform" Action = "javascript: void (null);" onsubmit = "submitsignup ();">
Username: <input type = "text" name = "username" value = ">
<Input type = "button" name = "check" value = "check only one" onclick = "submitsignup ();">
<Input type = "Submit" id = "submitbutton" name = "Submit" value = "Submit">
</Form>

<Div id = "usernameinfo" class = "errorspan"> </div>

</Body>
</Html>

You can see the statement in front of this Code: require_once ("../xajax. Inc. php "). Xajax. Inc. PHP is a file that defines related class libraries such as xajax. This file also contains a large number of Javascript script files and other constant definitions. The xajax class has its own attributes and methods, which take over and encapsulate the original Ajax behaviors and methods and are used to process user events and the attributes and appearances of page document objects.
The Ajax framework has its own advantages. However, due to too many Ajax frameworks, each has its own advantages and disadvantages, especially for the PHP language, it is difficult for us to select one of the frameworks that best suit our own projects. Too many frameworks increase the cost of communication. The framework itself reduces Code complexity and brings about learning costs. Unlike. net, companies backed by rich wealth can develop web and desktop applications with a set of libraries, a set of general ides, and a proficient language (such as C.
At last, please note that AJAX is not a panacea, and you may want to use it for any project. Currently, most Ajax applications are used in data verification and other applications, so be careful when using them in projects.

Zhang Qing (mesh) Co., http://blog.why100000.com.
Http://www.why100000.com:
2010-1-22

Related Article

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.