Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are some good JavaScript/AJAX interface patterns for websites?

I really like how sites like FogBugz and Facebook offer snappy user interfaces by loading page content asynchronously.

What are some good resources and patterns for applying this to other websites? I am looking for a solution that creates a unique hash URL for each page, preserves history and basic browser functions, and degrades gracefully if JavaScript is not enabled (a great example of this is Facebook).

This blog post is a good start, but it's far from a complete solution/pattern - and any approaches using jQuery would be great.

like image 672
Craig Smitham Avatar asked Sep 10 '10 21:09

Craig Smitham


People also ask

Which is more appropriate to used using JavaScript or using AJAX?

AJAX is not a scripting language; rather it is a framework that is used with JavaScript client side and server side technologies to provide unified user web page experience. AJAX, which is built on comprehensive frameworks and libraries, allows for a more sophisticated extension of JavaScript programming.

Is AJAX or JQuery better?

While JQuery is a library for better client-side web page development, AJAX is a technique of doing XMLHttpRequest to the server from the web page and sending/retrieving data used on a web page. AJAX can change data without reloading the web page. In other words, it implements partial server requests.

Is AJAX better than other client side technology?

Reduce server traffic and increase speed The first and foremost advantage of Ajax is its ability to improve the performance and usability of web applications. To explain more detailedly, Ajax techniques allow applications to render without data, which reduces the server traffic inside requests.


2 Answers

IMO, in order to allow a site to degrade gracefully, you should first build at least the framework of the site in the lowest level that you're going to support. In your case, this is going to be standard postbacks.

Once you've got this in place, you can then start adding ajax interactions.

The approach I've taken when using ASP.NET MVC is to have one function which builds the whole page from scratch (for regular postbacks) and then have some extra methods which I used to dynamically refresh content via Ajax. If I want to implement a 'Single Page' method like oyu describe then I would handle the onclick event of a hyperlink and call an ajax method that renders the 'Build Whole Page' method to a string then pump that string into my content div.

HTH

like image 70
Jason Summers Avatar answered Nov 07 '22 04:11

Jason Summers


I have found pjax to be the most promising solution so far. From https://github.com/defunkt/jquery-pjax:

pjax loads HTML from your server into the current page without a full reload. It's ajax with real permalinks, page titles, and a working back button that fully degrades.

pjax enhances the browsing experience - nothing more.

You can find a demo on http://pjax.heroku.com/

like image 20
Craig Smitham Avatar answered Nov 07 '22 03:11

Craig Smitham