|
|
Writing Your Server-Side Ajax Handler
|
03/22/2006, By Matthew Batchelder
|
In my recent post on Ajax; Templating; and the Separation of Layout and Logic, I refer to an Ajax Handler that sits server side to handle Ajax calls. Some elaboration is in order.
As I have stated in the past, I'm a huge fan of Prototype AND I choose PHP as my language of choice...so my examples will be using both, but the idea is portable.
The Eval Method - A Dynamic Handler
This method is one that I toyed around with for a while and I'll admit that its pretty simple and clean but there are some drawbacks. We're going to make a few assumptions: All requests will be GET (this is to keep things simple for this example) and we will keep the complexity of .htaccess sweetness out of these examples and assume that each call will be passing a function variable that specifies the function we are calling.
Handler scripts make the Ajax magic happen and the separation of handler logic from your application logic is just as important for robust development and debugging as the need for separation of layout and logic. Play around with the above methods and see which works for you. If you have a method all your own, I'd be interested to hear it!
Read more...
|
Rate this Ajax Articles
Rating: 5.5 out of 4 votes cast
| |
|
|
|
|
|
|
|
|
|
|
|
|