Filed Under (General) by Wenbert on 20-03-2008
Here is how to do it in Zend Framework.
Let’s start with the form:
<textarea id= "mytext">
</textarea>
<input type= "button" id= "mybutton" value= "go" />
< script language="Javascript">
//jQuery stuff
$(document).ready(function() {
$("#mybutton").click(function() {
$.post("< ?=$this->baseUrl?>/path/to/my/coolaction",{
mytext: $(‘#mytext’).val()
}, function(data){
//alert("Data Loaded: " + data);
obj = window.eval(data);
alert("Saved: "+obj[‘mytext’]);
},"json");
});
});
< / script>
In your controller-action:
public function coolAction ()
{
try {
if ($this->_request-> isPost()) {
//Do something that will save the $_POST to the database here.
$json = Zend_Json:: encode($_POST);
echo $json;
} else {
throw new Exception ("Invalid action. Not post");
}
} catch (Exception $e) {
echo $e-> getMessage();
}
}
Filed Under (General) by Wenbert on 07-12-2007
A short but complete tutorial on how to write a Chat Application using PHP, AJAX and XML.
Developers talk a lot about community when the term Web 2.0 comes up. And whether you think it’s hype or not, the idea of engaging your customers or readers in an instantaneous conversation about the topics at hand or the products you’re selling is pretty compelling. But how do you get there? Can you put a chat box on the same page as your product listing so that your customers don’t have to install special software or even Adobe Flash Player? Sure! Turns out, you can do it all with free, off-the-shelf tools such as PHP, MySQL, dynamic HTML (DHTML), Ajax, and the Prototype.js library.
Without further ado, let’s jump right into the implementation.

Filed Under (General) by Wenbert on 22-11-2007
I found this:
jRails is a drop-in jQuery replacement for Prototype/script.aculo.us on Rails. Using jRails, you can get all of the same default Rails helpers for javascript functionality using the lighter jQuery library.
jRails provides drop-in functionality for these existing Rails methods.
o Prototype
o form_remote_for
o form_remote_tag
o link_to_remote
o observe_field
o observe_form
o periodically_call_remote
o remote_form_for
o submit_to_remote
o Scriptaculous
o draggable_element
o drop_receiving_element
o sortable_element
o visual_effect
o RJS
o hide
o insert_html
o remove
o replace
o replace_html
o show
o toggle
Click here.
Filed Under (General) by Wenbert on 21-10-2007
Here is an excerpt from a book - Beginning Ajax with PHP: From Novice to Professional.
While the concept of Ajax contains a handy set of functionality for creating actions on the fly, if you are not making use of its ability to connect to the server, you are really just using basic JavaScript. Not that there is anything truly wrong with that, but the real power lies in joining the client-side functionality of JavaScript with the server-side processing of the PHP language using the concept of Ajax.
Throughout this chapter, I will run through some examples of how PHP and Ajax can be used together to design some basic tools that are quite new to Internet applications but have been accessible to desktop applications for ages. The ability to make a call to the server without a page refresh is one that is quite powerful, if harnessed correctly. With the help of the powerful PHP server-side language, you can create some handy little applica-tions that can be easily integrated into any web project.
Why PHP and Ajax?
So, out of all of the available server-side processing languages (ASP, ASP.NET, ColdFusion, etc.), why have I chosen to devote this book to the PHP language, as any of them can function decently with Ajax technologies? Well, the truth is that while any of the afore-mentioned languages will perform admirably with Ajax, PHP has similarities with the JavaScript language used to control Ajax—in functionality, code layout, and ideology.
PHP has been and will likely continue to be a very open form of technology. While code written in PHP is always hidden from the web user, there is a massive community of developers who prefer to share and share alike when it comes to their code. You need only scour the web to find an abundance of examples, ranging from the most basic to the most in-depth. When comparing PHP’s online community against a coding language such as ASP.NET, it is not difficult to see the differences.
JavaScript has always been an open sort of technology, largely due to the fact that it does not remain hidden. Because it is a client-side technology, it is always possible to view the code that has been written in JavaScript. Perhaps due to the way JavaScript is handled in this manner, JavaScript has always had a very open community as well. By combining the communities of JavaScript and PHP, you can likely always find the exam-ples you want simply by querying the community.
To summarize why PHP and Ajax work so well together, it comes down to mere func-tionality. PHP is a very robust, object-oriented language. JavaScript is a rather robust language in itself; it is sculptured after the object-oriented model as well. Therefore, when you combine two languages, aged to maturity, you come away with the best of both worlds, and you are truly ready to begin to merge them for fantastic results.
Client-Driven Communication, Server-Side Processing
As I have explained in previous chapters, there are two sides to a web page’s proverbial coin. There is the client-side communication aspect—that is, the functionality happen-ing right then and there on the client’s browser; and the server-side processing—the more intricate levels of scripting, which include database interaction, complex formulas, conditional statements, and much, much more.
For the entirety of this book, you will be making use of the JavaScript language to handle the client-side interaction and merging it seamlessly with the PHP processing lan-guage for all your server-side manipulation. By combining the two, the sky is truly the limit. Anything that can be imagined can come to fruition if enough creativity and hard work is put into it.
Basic Examples
In order to get geared up for some of the more intricate and involved examples, I will begin by showing some basic examples of common web mini-applications that work well with the Ajax ideology. These are examples you are likely to see already in place in a variety of web applications, and they are a very good basis for showing what can be accomplished using the Ajax functionality.
Beyond the fact that these applications have become exceedingly popular, this chap-ter will attempt to guide you as to what makes these pieces of functionality so well-suited to the Ajax concept. Not every application of Ajax is necessarily a good idea, so it is important to note why these examples work well with the Ajax concept, and how they make the user’s web-browsing experience better. What would the same application look like if the page had to refresh? Would the same functionality have even been possible without Ajax, and how much work does it save us (if any)?
Filed Under (General) by Wenbert on 17-10-2007
Java Passion provides an 18-week AJAX online course for free. I’m not sure if the guy responsible for this was the same guy I saw a couple of years ago in Waterfront Cebu - when I was attending a seminar/conference. He was discussing Java + AJAX along with other Java advocates.
Here is the outline of the course:
In general, the contents (presentation, hands-on labs, and homework’s) will be ready on the dates specified below. Due to the fast pacing nature of the Ajax technology, the contents are constantly being changed and improved even after the dates specified.
- Ajax Basics & Development Tools (Oct 15th, 2007, Week #1)
- JavaScript Basics and DOM APIs (Oct. 22nd, 2007, Week #2)
- Ajax Frameworks and Toolkits (Nov. 5th, 2007, Week #3)
- Ajax Application Examples (Nov. 12th, 2007, Week #4)
- Dojo Toolkit Basics (Nov. 26th, 2007, Week #5)
- Dojo Toolkit Advanced (Dec. 3rd, 2007, Week #6)
- ProtoType (Dec. 10th, 2007, Week #7)
- JSON (Dec. 17th, 2007, Week #8)
- Mashup (Jan. 7th, 2008, Week #9)
- Direct Web Remoting (DWR) (Jan. 4th, 2008, Week #10)
- Google Web Toolkit (Jan. 28th, 2008, Week #11)
- JavaServer Faces (JSF) and Ajax Integration (Feb. 4th, 2008, Week #12)
- jMaki (Feb. 18th, 2007, Week #13)
- Web Application Frameworks and Ajax (Feb. 25th, 2008, Week #14)
- CSS (March 10th, 2008, Week #15)
- Portlet/Portals and Ajax - (March 17th, 2008, Week #16)
- JavaScript Best Practices (April 7th, 2008, Week #17)
- ZK Framework
- Phobos (Script-based MVC framework) (March 31st, 2008, Week #17)
- Dissecting the Java BluePrints Petstore 2.0 Reference Application - work in progress
- Ajax Design Patterns and Best Practices - work in progress
- DynaFaces (April 14th, 2008, Week #18) -
- Commercial framework/tools (Backbase, JackBe, Tibco) - work in progress
Click here for the free training.
Filed Under (General) by Wenbert on 28-08-2007
I have posted a sample code on my wiki on how to submit variables to an action controller. The sample code contains a niffty jQuery plugin - the jQuery Calendar.
Click here for the tutorial.
Update (05-07-2008): Since this post has been getting a lot of traffic and the tutorial to my wiki is not that good, I have decided to update this page and post a simpler and shorter tutorial.
So here it is…
The Javascript will look something like this:
//For Edit Action
f u n c t i o n editnote(notes_id)
{
//a sample loading image thingy
$(‘#notes_entry_id’).prepend("<div id=’loading’><img src=’"+baseUrl+"/images/loading.gif’/></div>");
//Get notes from database - in ZF, notes = controller and getnoteforedit = action
$.post(baseUrl+"/notes/getnoteforedit",{
notes_id: notes_id
}, function(data){
$(‘#loading’).remove();
obj = window.eval(data);
$(‘#textarea_id’).val(obj[‘notes’]);
}, "json"); //this returns JSON.
}
Then my controller would look something like this:
/**
* Get note for action
*
*/
public function getnoteforeditAction ()
{
$this->_helper-> layout-> disableLayout(); //disable layout
$this->_helper-> viewRenderer-> setNoRender(); //suppress auto-rendering
//the 2 lines above are very important. this action would return html tags from the layout and will look for a phtml file. we disable the layout and suppress auto-rendering of the phtml view files SO that our JSON will be echoed properly to the Javascript…
require_once(‘models/Notes.php’);
require_once(‘models/UsersNotes.php’);
try {
if (! $this->_request-> isPost()) {
throw new Exception (‘Invalid action. Not post.’);
}
$Notes = new Notes ();
$data = array();
if ($result = $Notes-> fetchRow("notes_id=". $Notes-> getAdapter()-> quote($_POST[‘notes_id’]). "")-> toArray()) {
$data[‘notes_id’] = $result["notes_id"];
$data[‘notes’] = $result["notes"];
$data[‘datetime_posted’] = $result["datetime_posted"];
$data[’status’] = $result["status"];
$json = Zend_Json:: encode($data); //basically, $data array will also be available in the JS.
} else {
throw new Exception (‘Note ID not found.’);
}
echo $json; //this will echo JSON to the Javascript
unset($json);
unset($data);
} catch (Exception $e) {
echo $e-> getMessage();
}
}
That’s about it… 
The $data that was encoded using Zend_JSON in the controller/action can now be accessed in the Javascript after you call the eval().
Filed Under (Uncategorized) by Wenbert on 28-08-2007
I have been using PHP with jQuery so this one caught my attention.
It’s easy to get caught up in the dynamic potential of Ajax. But with innumerable possibilities also comes increased risk. If security isn’t a major concern, it should be.
Consider a registration form built out of PHP. Any aspect of your script that accepts and processes data is a potential point of attack. If you add Ajax, what you’re doing is increasing the complexity of the application and, by extension, introducing greater vulnerability. More points of entry equal a larger attack surface, and that means potential problems for your application.
Get the article here.
Filed Under (Uncategorized) by Wenbert on 08-08-2006
I just found this on Slashdot. A very interesting read since I am planning to dive into AJAX as soon as I get my hands free from the projects I have right now. Also, hopefully, I will also be working on a new company. hehe.
I am particularly interested in Dojo. It is supported by big companies like IBM and Sun. So I think it will outlast the others.
Here are a couple interesting images I got from Infoworld.

A snippet from Dojo:
If there is one open source AJAX project that is leading the pack these days, it might be Dojo. It’s not necessarily better in any particular way than the others, but it is both broad and deep with a big selection of very customizable widgets. These traits may explain why both IBM and Sun have recently signed on to support the Dojo Foundation and its work.
The project Web site and the code have the flavor of an exceptionally fertile open source project run by a neutral team of enthusiastic developers. The management is clearly aiming to encourage a wide range of contributions — as long as they fit Dojo’s basic philosophy demanding simplicity and clarity.
Dojo has an excellent editing package, a wide selection of animating boxes, some drag-and-drop tools, and much more. A tool for providing maps from Google and Yahoo just appeared in the latest 0.3.1 version.
I feel, however, that Dojo suffers a bit from the kitchen-sink-like quality of popular open source projects. Some parts of the library are well-documented and illustrated by a set of good demo pages. Other parts have little documentation, leaving developers on their own — the manual as well as the book describing the project have large holes typical of volunteer-built documentation.
Adding a bit of the Dojo toolkit to your Web application is pretty easy. The source code is modular, so your application only needs to load the necessary pieces using Dojo’s loading mechanism. In many cases, all you need to add is an extra attribute, dojoType, to your working HTML, and the code will do the work when it loads the page.
Dojo continues to improve as it attracts more developers with more ideas and code from other projects. The leaders are doing a good job of keeping these contributions in order, and there’s every reason to expect more sophistication in the future.
Source: Surveying open-source AJAX toolkits
By: Peter Wayner - July 31, 2006
|
|