The AJAX revolution has completely reinvigorated the web. Browsers are working hard to increase the speed of their JavaScript and rendering engines. Web Developers are working as quickly as possible to push the limits of the browsers even further. Users are feeling more entitled by the user experiences provided by AJAX-heavy websites like Facebook. Before you thrust your website into the world of AJAX, be sure you’re doing it for the right reasons, otherwise you may run into the following annoyances.
AJAX Archives
AJAX Annoyances to Avoid
Animated AJAX Record Deletion Using Dojo
I’m a huge fan of WordPress’ method of individual article deletion. You click the delete link, the menu item animates red, and the item disappears. Here’s how to achieve that functionality with Dojo JavaScript.
The PHP – Content & Header
The following snippet goes at the top of the page:
if(isset($_GET['delete'])) {
$query = 'DELETE FROM my_table WHERE item_id = '.(int)$_GET['delete'];
$result = mysql_query($query,$link);
}
The following is used to display the records:
Using Dotter for Form Submissions
One of the plugins I’m most proud of is Dotter. Dotter allows you to create the typical “Loading…” text without using animated images. I’m often asked what a sample usage of Dotter would be; form submission create the perfect situation. The following code changes a submit button’s text to “Submitting…” (and animated dot patterns) during the submission process, resetting the button text when the AJAX request is complete.
Record Text Selections Using MooTools or jQuery AJAX
One technique I’m seeing more and more these days (CNNSI.com, for example) is AJAX recording of selected text. It makes sense — if you detect users selecting the terms over and over again, you can probably assume your visitors are searching that term on Google, Yahoo, etc. I’ve duplicated this functionality using my favorite JavaScript library, MooTools, and another JavaScript library, jQuery.
Form Element AJAX Spinner Attachment Using jQuery
Yesterday I showed you how to attach an AJAX spinner next to a form element using my beloved MooTools. Today I’ll show you how to implement that same functionality using jQuery.
The XHTML
<select class="ajax"> <option value="">-- Select a Site--</option> <option value="David Walsh Blog">David Walsh Blog</option> <option value="Script & Style">Script & Style</option> <option value="Band Website Template">Band Website Template</option> </select> <br /><br /> <input type="text" id="my-text" class="ajax" />
Elements with the “ajax” CSS class will be our target.