Provides an easy way for plugin/theme developers to use Xajax framework to write ajax applications.
For an overview on how to use XAjax and complete documentation, visit its wiki at http://xajaxproject.org/wiki/.
Here you find a very pratical tutorial on how to write a wordpress plugin using xajax. This tutorial is based on the great “Learn xaja in 10 minutes”, wich you find here: http://xajaxproject.org/wiki/Tutorials:Learn_xajax_in_10_Minutes
How to write a plugin using wp-xajax.
- Install wp-xajax
Obviusly you have to install it at first. Nothing will happen when you activate it, thats the way it is.
- Write your php function
This function can do anything you like: access the database, send emails, call other functions.. whatever.
The only thing this function can not do is to produce any output to the screen. It cannot have any “echo” calls.
In the next step we will see how to send output to the screen. So, lets say we want a function to send an email:
$friends = 'email@example.com,firstname.lastname@example.org'; mail($friends, "blog updated", 'I just put something on my blog: http://blog.example.com');
This function does not receive any argumnent, but you can have a function that receives as many argumnents as you like.
- Add some response to your function
Lets say you have a div next to your button with the id “response_div”. Then you can add this to you function:
$friends = 'email@example.com,firstname.lastname@example.org'; mail($friends, "blog updated", 'I just put something on my blog: http://blog.example.com'); $objResponse = new xajaxResponse(); $objResponse->addAssign("response_div","innerHTML","Email Sent!"); return $objResponse;
You will allways interact with the page objects using their ids. There are many ways in wich you can interact, have a look at
the full doc here: http://xajaxproject.org/wiki/Documentation:xajaxResponse.inc.php
- Call your function
So you may have a button, and add to this button the event Handler:
input type=”button” onclick=”xajax_myplugin_sendEmail()”;
- Register your function
Create a function that will register your xajax_function as follow:
And then add an action to call it: