First, Hellowrold step PHP code//server-side require_once (... /.. /xajax.inc.php); Define the handler function,//and Xajaxresponse the object in the handler function
First, hellowrold steps
PHP code
Server-side
Require_once (".. /.. /xajax.inc.php ");
Defines a handler function,
And the instance Xajaxresponse object in the handler function.
Call its method to control the value of the control, and then return the object
function MyFunc ($text) {
Instance Response Object
$objResponse = new Xajaxresponse ();
Change the value of a control
$objResponse->addassign ("Div1", "InnerHTML", $text);
return $objResponse;
}
Initialize Xajax
$xajax = new Xajax (); You can specify a server-side responder
$xajax->registerfunction ("MyFunc"); Registering a handler function
Start accepting requests
$xajax->processrequests ();
PHP code
Client (client and server side should share the same Xajax object, can be made public profile)
Add a script to the
$xajax->printjavascript ('.. /'); Available variables, parsed by template
Define a control that accepts new content
<div id= "Div1" name= "Div1" > </div>
Execution method, xajax_ as prefix, MyFunc for registered function name
<button onclick= "xajax_myfunc (' Hello ')" >click me</button>
Summary: First constructs a Xajax object for the server side and the client to share, then defines the corresponding processing function (constructs the Xajaxresponse object in the function, and uses this object's addassing and so on the client control operation), Register the handler function and start running using the Processrequests method. The client needs to invoke the Xajax object's Printjavascript method to generate the JavaScript code (added to the head segment), and then define the event that triggers the handle, which is called " Xajax_ "+ Registration function name, which can be modified when initializing Xajax
Ii. Common methods
Xajax object:
Xajax ($sRequestURI = "", $sWrapperPrefix = "Xajax_", $sEncoding =
Xajax_default_char_encoding, $bDebug =false);
constructor, $sRequestURI the server URI, $sWrapperPrefix the prefix when the client calls, $sEncoding encoding
Registerfunction ($mFunction, $sRequestType =xajax_post)
Register the handler function, $mFunction the function name, $sRequestType commit the Class shape, the other choice is Xajax_get
You can use the class method:
Registerfunction (array "MyFunc",& $myObj, "MyMethod"));
' MyFunc ' for front-end call Function name $myObject, class instance ' MyMethod ' class method
Registerexternalfunction ($mFunc, $sIncludeFile, $sRequestType =xajax_post)
$sIncludeFile contains the external file path of the function definition, and other registerfunction used to introduce a separate function definition file
Registercatchallfunction ($mFunction)
Defines a default handler that performs this operation when the current end calls a function that does not exist
Registerprefunction ($mFunction)
Defines a preprocessing function that calls any function on the front end and calls this method first
Processrequests ()//Start execution
Printjavascript ($sJsURI = "", $sJsFile =null)
Output front-end JavaScript code,
Getjavascript ($sJsURI = "", $sJsFile =null)
Output the JavaScript code that is applied to the front-end to the variable so that the template engine uses the
Xajaxresponse objects
Xajaxresponse ($sEncoding =xajax_default_char_encoding, $bOutputEntities =false)
constructor that indicates whether to encode or convert HTML tags
Setcharencoding ($sEncoding); Change the encoding
Addconfirmcommands ($iCmdNumber, $sMessage)
User confirmation action. $iCmdNumber If you choose ' Cancel ', the number of commands to skip, $sMessage the message
Addassign ($sTarget, $sAttribute, $sData)
Changing the value of the $sattribute attribute of $starget to $sdata;
Addappend ($sTarget, $sAttribute, $sData)
Add the new value to the back of the original value
Addprepend ($sTarget, $sAttribute, $sData)
Insert the new value in front of the original value
Addreplace ($sTarget, $sAttribute, $sSearch, $sData)
Replace the $ssearch in the original value with $sdata
Addclear ($sTarget, $sAttribute)//Clear Original value
Addalert ($SMSG)//Generate an Alert dialog box
Addredirect ($sURL)//redirect
Addscript ($sJS)//execute JavaScript code
Addscriptcall ("Myjsfunction", "Arg 1", "Arg 2", 12345);
Call JavaScript function myjsfunction
AddRemove ($sTarget)//Removing an element
Addcreate ($sParent, $sTag, $sId, $sType = "")
Add a child element to the $sparent $stag
inserting elements
Addinsert ($sBefore, $sTag, $sId)
Addinsertafter ($sAfter, $sTag, $sId)
Add Form Item
Addcreateinput ($sParent, $sType, $sName, $sId)
Addinsertinput ($sBefore, $sType, $sName, $sId)
Addinsertinputafter ($sAfter, $sType, $sName, $sId)
Join Event Handling
Addevent ("Contentdiv", "onclick", "alert (' Hello world ');");
Adding the onclick event for the Contentdiv control
AddHandler ($sTarget, $sEvent, $sHandler)
AddHandler ("Contentdiv", "onclick", "Clickit");
Add Onclic event for Contentdiv, execute JavaScript method Clickit
Removal Event Handling
Addremovehandler ("Contentdiv", "onclick", "Content_click");
Add external JS file
Addincludescript ("Functions.js");
Returns response, which can be returned directly to $ajaxresponse ();
GetXML ()
In addition: In the front-end program, you can submit the form's value to the backend using the following method
Xajax_myfunc (xajax.getformvalues (' formid '));
The ID of the form is passed in, if the second argument is true; the value of the control with the Disable property in the form is also passed in