Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 AJAX: What have you done?
Index -> General Programming
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
jeffgreco13




PostPosted: Thu Jul 17, 2008 8:09 am   Post subject: 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.
Sponsor
Sponsor
Sponsor
sponsor
Vermette




PostPosted: Thu Jul 17, 2008 9:06 am   Post subject: Re: AJAX: What have you done?

If your server side code was Java, I'd HIGHLY recommend looking into DWR. It generates all the AJAX boilerplate for you, so someone like myself who isn't so comfortable on the web design front can bridge together javascript and Java code with no effort.

For example, if I had the following Java method sitting in a class on the server

Java:

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

Javascript:

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 Razz
Zeroth




PostPosted: Thu Jul 17, 2008 10:08 am   Post subject: 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




PostPosted: Thu Jul 17, 2008 10:12 am   Post subject: Re: AJAX: What have you done?

I'm a sucker for Apple's new AJAX-y search box. It's a practical and useful way to use AJAX.

Also be sure to check out jQuery to make your life easier.
Unforgiven




PostPosted: Thu Jul 17, 2008 11:15 am   Post subject: RE:AJAX: What have you done?

I've mostly just done AJAX in the context of replacing the contents of containers (<3 the innerHTML property). Nothing too fancy.
Aziz




PostPosted: Thu Jul 17, 2008 1:09 pm   Post subject: RE:AJAX: What have you done?

I haven't touched AJAX yet ;/ the more I learn to more I find out I don't know.
jernst




PostPosted: Thu Jul 17, 2008 1:24 pm   Post subject: Re: AJAX: What have you done?

Ive used ajax to modify someones wordpress blog. Its a site for a teacher who wanted to provide a resource section for people to upload content into, search, browse and download. He wanted it integrated into the look of the site so I used the ajax to pull everything into a wordpress page
DemonWasp




PostPosted: Fri Jul 18, 2008 8:48 am   Post subject: RE:AJAX: What have you done?

I worked as part of a team developing an internal-use-only web-service which was powered by AJAX (because reloading pages took forever, and this was actually easier...and we actually used Asynchronous Javascript and JSON, not XML).

We used the YUI library to make coding the JS easier, and Java on the server side. I was mostly doing the webdev stuff, and if you know what data you want, YUI has excellent facilities for sending information back to the server, and even better facilities for making the browser more like a platform for a dynamic application than a static display.
Sponsor
Sponsor
Sponsor
sponsor
Unforgiven




PostPosted: Fri Jul 18, 2008 2:27 pm   Post subject: RE:AJAX: What have you done?

You know, I've read a bit on JSON and whatnot, and I just can't see any reason why anyone would use XML over JSON in a streaming data sort of app like AJAX (well... AJAJ? You get the idea, term used loosely).

Am I missing something?
Zeroth




PostPosted: Fri Jul 18, 2008 2:53 pm   Post subject: Re: AJAX: What have you done?

Because XML was first, and is espoused by certain industry individuals* as being the solution to all of developments problems. XML does have the advantage that the data can be verified.


*Read: People that have a tool, that is $500/year/computer that will use XML to solve all your problems!
DemonWasp




PostPosted: Fri Jul 18, 2008 3:07 pm   Post subject: RE:AJAX: What have you done?

As noted, XML can be verified, and it can also be dealt with by existing libraries. It has additional features (part of why JSON is simpler and smaller). It can also be manipulated by XSLT, which JSON cannot.

But you're essentially right. For pure data-transfer, JSON is much more efficient, both in bandwidth and in parse speed.
Unforgiven




PostPosted: Fri Jul 18, 2008 3:08 pm   Post subject: RE:AJAX: What have you done?

Yeah, it seems for storage, or in cases where easy public access is a major concern, XML is good, but when I'm just updating a <div> or something from my own script... screw it, I just want it light, fast, and small.
Display posts from previous:   
   Index -> General Programming
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 12 Posts ]
Jump to:   


Style:  
Search: