The Xajax class of Ajax

Source: Internet
Author: User

Xajax Web Development Step 1. Building objects and initializing settings

Require_once ("./xajax/xajax_core/xajax.inc.php"); Include class file

$xajax = new Xajax (); Creating objects

$xajax->configure ("JavaScript URL", "./")//Set JavaScript path

Autocompressjavascript ('./xajax/xajax_js ');

The path program can set itself, the algorithm is very sophisticated, generally do not error.

2. Register the response function

Operations that handle request/generate response functions can be encapsulated in a custom "response function", and the Xajax object created in the previous step registers a "response function" by invoking the Register () method, which means that Xajax knows who to call when an asynchronous request occurs.

$xajax->register (xajax_function, ' adding '); Registering a response function

The Xajaxrequst class provides a way to generate this program.

To generate the JavaScript program code for the client call response function, the Xajaxrequest object that it returns must be obtained when the response function is registered. (That is, the Xajax->register () function returns the Xajaxrequest class object).

Addparameter () method for 1XajaxRequest class objects

The purpose of this method is to set the parameters to be added to the client's xajax_xxx () call. The way to join is to specify the type of the parameter and the parameter value when the method is called.

$Request->addparameter (stype, svalue)

Where: stype: Parameter type svalue: Parameter value

Type: xajax_form_values

Xajax_input_values

Xajax_cheked_values

Xajax_element_innerhtml

Xajax_js_value is so much better

2 Call the Printscript () output client's xajax_xxx () at the location where the JavaScript program needs to be called.

such as onclick= "$Request->printscript ()";

3. Please xajax handle asynchronous requests

$xajax->processrequest (); Handling Asynchronous requests

L Determine which response function is called by the client.

L HANDLE the response function called by the parameters sent in the client request.

After the response function has been processed, ProcessRequest will call exit () to end the program.

4. Writing response functions

After registering the response function with the register () method, you must write the response function to return the processed results.

The response function is to set the content of the response using the Assign () method of the Xajaxresponse class object.

$objResponse =new xajaxresponse ();

$objResponse->assign ($sTarget, $sAttribute, $sData);

Where: $sTarget: The ID of the HTML element to set.

$sAttribute: The name of the property to set.

$sData: The fill content to set.

The 1assign () method specifies that the contents of a tag are changed to produce a response to the client data.

2append (), prepend () These two method usages and syntax are similar to assign (), except that the data is "appended" to the back/front of the specified tag's existing data.

3$objresponse->alert (' Information from PHP ');

The parameter of alert () is a literal message that causes the client to execute Javascript alert () To display the message box.

4call () calls this method on the client's JavaScript function for the parameter.

$objResponse->call (' Test ');

The 5script () method is to execute a JavaScript program on the client, which must be called a "client to execute Program" (string) as a parameter of script ().

$objResponse->script (' Window.close () ');

The purpose of the 6redirect () method is to have the client redirect the Web page that the parameter refers to.

$objResponse->redirect (' http://www.flag.com ');

5. Output JavaScript Program code

The last thing to deal with is the client's JavaScript program, although we do not have to write Ajax JavaScript programs, but still need to ask Xajax to help output these programs.

You can output xajax JavaScript code by calling Xajax's Printjavascript () method in the

$xajax->printjavascript (); The parameters here are related to the correct URL setting

Error message:

Error:the Xajax JavaScript component could not be included.

Perhaps the URL is incorrect?

Url:.. /xajax_js/xajax_core.js

In the Printjavascript () output program code, in addition to the Xajax shared part, it also produces the corresponding xajax_xxx () function for the previously registered PHP response function for us to use on the client.

Special Note: Asynchronous invocation is very useful in the framework. Asynchronous content is set to "Heredoc" or "Newdoc" (php5.3) content, can be implemented without reloading a page in the case of the display

Two or more of the content.

The Xajax class of Ajax

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.