JQuery…my new favorite Ajax framework

After a several stints with Dojo, Ext and Prototype, I decided to see if JQuery could provide anything better. I figure it’s a good thing to be versed in several Ajax frameworks. You never know which one you might use next really. I am definitely weary of Dojo and it’s lack of support and constant revamping to remove things that worked previously. I love Ext, but turning around and charging for it was really a bad idea on their part. I think they have the best forums and support and their API is really easy to use.
After looking into JQuery, I was pleasantly surprised to find out how lightweight it was. It is a tiny fraction of the size of the Dojo library and the syntax of use is more concise and direct. Of course, this lack of size is mainly because all of the widgeting control is included in other separate plugins that you can add on, but I do like that. It is simple to download a plugin or write your own. I really avoid writing something custom unless a last resort. There is always one out there ready for use.
So, I put JQuery into my project and I already had a Spring Controller using Content negotiation serving up my JSON and I gave it a whirl. It just a few minutes I was able to get data from the JSON object and then populate anything or do anything I wanted to do with it. I accomplished it in just a few lines of code.

$(document).ready(function(){

$.getJSON(“rest/DataService/loanTypes.json”,{id: $(this).val(), ajax: ‘true’}, function(j){

var options = ”;
var loanTypes = j.loanTypeList;

var currOptions = $(“select#loanTypes”).html(options);

for (var i = 0; i < loanTypes.length; i++) { options += '’ + loanTypes[i].loanType + ”;
}

$(“select#loanTypes”).html(options);

});

});

At first the $ notation takes a little getting used to, but just think of it as a dojo.byId on steroids. It’s a really powerful notation. This is just a snippet from the example, but I just get the JSON from the server and populate a select box manually creating option elements. Ordinarily I would frown upon doing this, but it’s just an example. A proper way would be to use a JQuery UI component that would just take the JSON automatically.

I found several plugins that were really useful on the JQuery site. I even used JQuery UI and another plugin to replace alert messages with Ajax Alerts.

Most of the other libraries out there are all very self contained, but JQuery just allows you to download plugins at will. This is very powerful but it has it’s drawbacks. You have to make sure that the plugin you download and all it’s dependencies all match with the supported versions of each. This can make upgrading JQuery difficult if you use a lot of plugins. I recommend using them cautiously.

You can find a list of all the JQuery plugins here.

http://plugins.jquery.com/

You can download and install JQuery into your project as simply as downloading the js file and including in your HTML page.

Go get it and try it out.

JQuery http://www.jquery.com

If you want support or see other examples of how other users are leveraging the framework, check out the forum.

http://forum.jquery.com/

Follow

Get every new post delivered to your Inbox.