Go to content Go to navigation Go to search

Doing It The jQuery Way · Sep 5, 02:50 PM by Dylan Doxey

Here's (a slimmed version of) one of the more intersting bits of JavaScript code I've written recently.

    var refresh_ui = function() {

        $('#keyword_select').load('/keywords?action=list');
    }

    var save = function() {

        var item_id  = $('#item_select').val();
        var keywords = $('#keyword_select').val();

        return $.post( '/settings/keywords',
            {
                action   : 'save',
                item_id  : item_id,
                keywords : keywords,
            },
            refresh_ui
        );
    };

    $('#save_button').click(save);

This snippet illustrates several ways of doing things using jQuery that break from the old norm:

I used to pride myself on writing fancy AJAX interfaces for each individual application. But golly, nothing I ever did approached the simplicity and elegance of just doing $('#item').load('/url/path');.


Don't reinvent the wheel. Stand on the shoulders of giants and move on to developing something else.

Commenting is closed for this article.