
-----------------------------------
jeffgreco13
Thu Jul 17, 2008 8:09 am

AJAX: What have you done?
-----------------------------------
Looking for some input, stories code... anything you guys have done using AJAX. I'm really looking hard into it trying to learn how to make some pretty cool new things for a CMS im creating. Most likely will be incorporated with PHP and MySQL.

-----------------------------------
Vermette
Thu Jul 17, 2008 9:06 am

Re: AJAX: What have you done?
-----------------------------------
If your server side code was Java, I'd HIGHLY recommend looking into 
class DataMaker{
...
public TastyData foo(String bar, String baz){
  //insert whatever code you want, maybe you make a db call here and some data manipulation... whatever
  
  return tastyData;
}
...
}


With DWR I can simply write a call to that method in a javascript function


DataMaker.foo(bar, baz, 
  function(tastyData){
    //nom nom nom;
  }
);


That third parameter?  Since AJAX is asynchronous under normal circumstances the next line could begin execution before the TastyData is even returned.  So, DWR calls have that extra parameter tacked on at the end called a callback function, so you can be sure such code is not run until the data is returned.  All data returned through AJAX calls in DWR is serialized into JSON objects, and you can specify in an XML file custom object converters if you're dealing with some real funky objects.

I'm rambling here, but I just think DWR is really great.  Web design isn't my cup of tea so this has allowed me to implement AJAX calls without knowing AJAX.  Good or bad depending on your perspective, but quite handy to be aware of.  And that's what I've done with AJAX :P

-----------------------------------
Zeroth
Thu Jul 17, 2008 10:08 am

Re: AJAX: What have you done?
-----------------------------------
What I've done is a very small ajax-y function, that takes the user's current album index(which image they're looking at), and returns the next however many images. I used jQuery to make the call, it was pretty simple. Made the call, information comes back, add it to the gallery. The idea was to make a gallery that loads quickly for large N images, and so, it will pre-load images before you need them. On the Django side, I just added a new entry to my urls.py, created a new function that makes the database call, and I was homefree. It took me an hour, all told. The only hard part was making the rest of the javascript actually use the images.

-----------------------------------
rdrake
Thu Jul 17, 2008 10:12 am

Re: AJAX: What have you done?
-----------------------------------
I'm a sucker for Apple's new [url=http://www.apple.com/]AJAX-y search box.  It's a practical and useful way to use AJAX.

Also be sure to check out [url=http://jquery.com/]jQuery to make your life easier.

-----------------------------------
Unforgiven
Thu Jul 17, 2008 11:15 am

RE:AJAX: What have you done?
-----------------------------------
I've mostly just done AJAX in the context of replacing the contents of containers (