Click to See Complete Forum and Search --> : How do you handle your AJAX?
leatherback
07-06-2008, 03:07 PM
Hi,
After making a few sections with a few AJAX calls, I am n wgetting to the point that I would like to hadle much more with AJAX. I am wondering how you guys handle the AJAX.. Do you use a framework? Or do you write your own? If the latter; How do you organize it?
I mean, you can pretty much hadle all the processing on the server, and let js only replace ,div. content & make the AJAX calls. Of you can push most routines to the js side and have php do minimal stuff.
Wondering how you guys choose to run it all, and avoid being burried in individual js functions
dougal85
07-06-2008, 07:25 PM
I tend to use a JS framework. Just because it makes cross browser stuff easier. I've used Prototype quite a bit but there are loads of good options out there. Also, the other good thing about using a framework is they update the framework for new browsers and then you shouldn't have such a headache adding support down the line.
In terms of the server side I tend to add a GET var called ajax to calls and instead of rended HTML it returns the data encoded in JSON. I guess it all depends how you structure your code at the back end...
On smaller websites that I've put together quickly I've just had an ajax.php that handled all the JavaScript requests.
foyer
07-09-2008, 11:41 AM
I recently built a website for a client using xajax (http://xajaxproject.org/) class library
bretticus
07-09-2008, 12:47 PM
I'm with dougal85, I like to use a framework. In fact, I'm pretty sold on prototype (http://prototypejs.org/api/ajax). And I use it for the same reasons (I don't have to worry about cross browser support, etc.) Another reason I have used it (example) is a list of options for a client. Prototype has an object called PeriodicalUpdater which allows me to keep the list updated in real time (think tickets for a show.) Now, noting that AJAX is basically using just one javascript object (XMLHttpRequest) one can build this stuff "from scratch" and keep his or her code lightweight (without all the bells and whistles.) For example, I could have probably found a way to use setInterval to continue calling my home-brewed AJAX-ian code and updating my list. However, I trust the implementation of PeriodicalUpdater and I didn't have to write any javascript (just call Ajax.PeriodicalUpdater.) Plus, it has tons of useful DOM building stuff when you pull back that data as JSON and eval() it (note, it can detect JSON header and eval the JSON for you.) On that note, I really like Builder from scriptaculous (http://github.com/madrobby/scriptaculous/wikis/builder) (which is an extension of Prototype for anyone who didn't already know.) Finally, check out how easy it is to submit a form (http://www.prototypejs.org/api/form/request) with Prototype.
Also, I saw a post the other day (can't remember sorry) where somebody was using ajaxslt (http://code.google.com/p/ajaxslt/). I suppose that means they use ajax to get XML and XSL templates and transform it on the fly to build DOM elements. I found a very basic demo (http://www.jongma.org/webtools/jquery/xslt/xslt-test.html) that uses ajaxslt.
PHP Builder
Copyright WebMediaBrands Inc. All Rights Reserved.