views:

715

answers:

12

I'm building a site that's sort of a cross between StackOverflow and Digg (only a different genre). Typically in the past I would have just built it using ASP.Net web forms. However I want to use this project as a way to learn new technologies. I'm using ASP.Net Mvc which is really great, but I need to learn/use some kind of javascript libraries.

For instance, when someone votes on a post I want it to be updated with the vote count immediately, or if someone types in text into the "tags" textbox, I want it to give a drop-down of currently used tags etc. Basically I want to provide a lot of the AJAXy stuff for my site.

So my question is where to I begin? I feel bombarded with so many options and I'm not sure where to start or even what they are. Can someone straighten me out and provide some explanation and direction?

  • JSON
  • JQuery
  • MS-AJAX

I'm sure there are bunch of others I can recall at the moment.

A: 

I would go with jQuery, lately its the one that has been getting more attention and you'd find better starting points / tutorials / things already done.

But if you're more eager to learn Javascript, then you shouldn't worry about the framework and learn the language basics at first... then use frameworks to help you do things quicker and better.

Luca Matteis
+4  A: 

I've always found that the rhino book is my friend when working with javascript. Although it does not cover the flashy frameworks it feels like it's always there as a backbone tutorial/reference with really solid coverage of everything. The latest editions also cover ajax stuff.

I have no less than 3 editions of this book, and they all look worn & well used.

krosenvold
+1 for the rhino book. It's a great reference.
Dana Robinson
A: 

JSON is not a library, so don't worry about that.

MS-AJAX is a very specific tool, so I wouldn't bother either, unless you are already a ASP.NET guy.

I would suggest you to get started with pure Javascript, and when you are comfortable with it try something like jQuery, which is awesome, and also John Resig's "Pro Javascript Techniques" that will twist your mind in a good way. While I was reading the book I was saying "wow that is really cool" on every 2nd page.

But the important thing is to get the basics first, so head for w3schools or get a nice javascript book at the shop.

rodbv
+2  A: 

Short answer: I think you start with jQuery.

Long answer: JSON isn't a library it's a data format, and a simple one at that. If you're familiar with javascript at all it should come naturally - it is essential to learn but it won't take long. jQuery is getting the traction to become the de-facto standard library and that includes with MS and other big players. It's quite straightforward to get started with and you'll find a ton of community support for it, not least here.

annakata
JSON is an optional library AND a data format. You can eval() JSON but there is a library called JSON, too, which makes life with the JSON format more manageable. http://www.json.org/ hosts it.
stimpy77
From the homepage of json.org "JSON (JavaScript Object Notation) is a lightweight data-interchange format." - there are many libraries and parsers hosted by json.org but none of them are called JSON. Got a URL?
annakata
I disagree with the idea that you should start with jQuery. You're starting at too high level of an abstraction and will get a false sense of JavaScript. Learn JavaScript, then learn jQuery.
Tom
the OP specifically said he wanted to learn libraries, obviously I agree you learn javascript first because you'll not get very far with jQuery without it
annakata
+6  A: 

Start by learning the basics of Javascript. It's important you know how to use it's internals before you dive into deeper abstractions. Mozila has a fantastic resource on Javascript, including an overview guide.

Next, pick up a good framework, it will help you a great deal performing DOM manipulations, which is what Javascript is generally used for. A framework will save much time on cross-browser implementation differences and provide a good base to develop from. There is plenty of selection here, and you'll do fine with either of the popular choices. Personally, I'd pick jQuery for its concise API and great plug-in library.

Along the way you'll learn the definitions of distinct features / notations, such as JSON (which means Javascript Object Notation, and is used to define portable data structures in Javascript). For any specific questions you have, you can always google or come back to SO ;)

Eran Galperin
A: 

jQuery has the distinct benefit that it has been blessed by Microsoft, so if you are using SO technology, that would be a good place to start (with the jquery site tutorials).

le dorfier
+25  A: 

You should definitely start with the basics of Javascript. Start with things like printing "Hello World" to the page. Move on to basic language features like variables, loops, conditionals, and functions. I recommend the W3Schools Introduction to Javascript. Don't get too caught up in trying to do object-oriented programming in Javascript. It is painful and confusing, even for some experienced Javascript programmers.

Next I strongly recommend learning to use a cross-browser Javascript library, rather than trying to do everything by hand (specifically: interacting with the DOM, performing XmlHttpRequests aka AJAX calls, etc.). I recommend the jQuery library. It provides a solid foundation for all of the cool AJAX-y things you want to do, and there are loads of plugins available for it.

jQuery is a Javascript framework that allows easy and reliable interactions with the Document Object Model (DOM). In simplest terms, the DOM is the representation of all the HTML elements in a web page. The DOM is slightly different from browser to browser, and interacting with it "by hand" is tedious and error prone. jQuery solves this problem by essentially doing all the hard work behind the scenes. It is much more powerful than that, really, but that's the major feature. It also provides support for page events, custom events, plugins, CSS manipulation, and much more.

JSON is another term you mentioned. It stands for JavaScript Object Notation. JSON is simply a lightweight way to represent structures in Javascript (and other languages too, actually). To be honest, the Wikipedia JSON Article provides a much better summary of how JSON is used with AJAX than I ever could, so you might want to give it a read.

Here is the basic order of events:

  1. Your Javascript code makes an AJAX call to a web page. You can do this using the AJAX functions in jQuery.
  2. The result produced by that web page is a JSON object. For example, it might produce a string that looks like: { 'firstname':'Robert', 'lastname':'Smith' }
  3. The result is received by your AJAX call and evaluated using the special Javascript "eval" function.
  4. You are left with a native Javascript object that you can work with in your code. You can then do stuff like: document.write('Hello ' + result.firstname + ' ' + result.lastname)

Here are a few useful links I have collected over the past year or so that have helped me. I hope they help you too!

The most important thing to remember is: learn by doing. Experiment. Try new things. Make a bunch of proof of concept pages. With Javascript, that's really the best way to get your feet wet. Good luck!

William Brendel
This is the epitomy of what a stackoverflow answer should be. Nice job. Thanks!
Micah
You're welcome -- I'm glad you found it helpful :-)
William Brendel
+1  A: 

Learn the basics first, then pick up a framework to learn the Ajax stuff - there are so many that there's no reason to do it by hand anymore. I second (third? fifth?) learning jQuery; it really looks sweet.

Wayne M
+2  A: 

JSON

JSON is a data format, like XML, but it's native to Javascript. You can eval() it and it becomes an actual object (more literally, a hashtable). It's an ideal replacement for XML for sending data back and forth asynchronously on the page because it needs no parser and because it has a smaller footprint. For the server side, there are a number of JSON libraries such as JsonFx Serializer that help you serialize/deserialize JSON on the server. More info including links to multiple JSON libraries at http://www.json.org/. Note that there are also a few optional Javascript libraries for working with JSON, also at json.org.

JQuery

jQuery is fast becoming the ultimate Javascript utensil library. It's literally one of the first, if not THE first, third party open source software that Microsoft has adopted and rolled into its development product line as a core component (for Visual Studio 2010 and for ASP.NET AJAX 4.0). This is definitely THE library you want to learn, but not before you have a full grasp of the fundamentals of Javascript first.

MS-AJAX

Microsoft ASP.NET AJAX is basically a set of extensions to ASP.NET Web Forms that facilitate AJAX functionality by performing postbacks to the server without refreshing the entire page. There's more to it than that; it also has an extensive Javascript library (Microsoft AJAX Library, I believe it's called, which is what "MS-AJAX" denotes) that provides a lot of .NET-like OOP features to Javascript, and it DOESN'T require ASP.NET AJAX to be utilized. The Microsoft AJAX Library (Javascript library) is not a BAD thing to learn, but it's not necessary. ASP.NET AJAX, however, is based on ASP.NET Web Forms, and as such it is not compatible with ASP.NET MVC. You can use the Javascript library but not to its fullest extent; again, it's not necessary, you can accomplish much with just knowing Javascript fundamentals very well and knowing jQuery (and jQuery plug-ins) very well.

In short, learn Javascript itself (if you haven't already), learn DOM manipulation / DHTML fundamentals as well, and then learn jQuery, and I think you'll be all set.

stimpy77
+1  A: 

I'd like to add a shout-out to the Yahoo User Interface libraries, which provide many of the basic "standardisation" layers that libraries such as jQuery do (e.g. DOM manipulation, event handling, etc.) as well as a fairly decent widget collection.

It may not have such concise syntax, but it's beautifully documented - including many other excellent materials worth reading - and has a massive raft of examples.

I felt it was worth pointing out, just so people consider multiple options.

Rob
A: 

If you do it "just for fun" you should probably read the other answers here. If you are focusing on the results it might be better to start with an existing codebase which e.g. Stacked could give you. Stacked is an Open Source implementation of StackOverflow, with some differences created for being more "flexible". Like for instance support for more then one database, lots of configuration things etc...

BTW, I do work with Stacked...

Thomas Hansen
+1  A: 

Don't miss this one: http://ajaxpatterns.org/

It contains a comprehensive coverage of all of the concepts and design patterns that you might use in AJAX development in any lib. It also includes a review of all the AJAX libraries. This site will give you the big picture rather than just teach you one specific lib.

Personally I like ExtJS AJAX Lib http://extjs.com . I used it for 6 months on a research project after reviewing the market place. I particularly liked its excellent suite of UI widgets. Check out their demos. This library was originally based on Yahoo UI but now has much more. They've now integrated it with Google web toolkit (which I nearly chose but for lack of decent widgets).

Libs like jQuery look tiny and incomplete beside this one. Dojo has some great stuff but is not as integrated and the code quality is not as high (IMHO). Downside for some might be the GPL / Commercial license terms (was orginally LGPL and the switch to GPL caused some controversy).

Checkout the rest of my AJAX resource links at http://delicious.com/tohagan/ajax ... Enjoy!

tonyo