jQuery Ajaxify

Probably not the first person to implement this, but I wanted to make an automatic form AJAX-‘ifier’ that could capture which submit button had caused the submit event to be fired too.

It’s implemented fairly simply:

$('form').ajaxify();

There’s a demo page or you can just download it and have a look.

Update: As pointed out by Andrea in the comments below, this would return the value of radio and checkboxes even if they weren’t selected. I have released 0.1a and updated the link above to fix this issue. Thanks Andrea!

Update 2: I have updated this plugin, view this post for more information.

Update October 2010: I have updated this plugin for jQuery 1.4.3 as a ‘lite’ version.

2 Replies to “jQuery Ajaxify”

  1. Your little ajaxify form script works great.. just one thing, it sends the value of a checkbox even when the checkbox is not checked. I’ve made the following change in the serializeform function to fix this:

    serializeForm: function(node) {
    // initialize the string
    r = ”;

    // loop through all the elements (except submits)
    $(node).find(‘input[type!=submit][type!=button][type!=image], textarea, select’).each(function(i, e) {
    // and appent the name and value to the string
    if( $(e).attr(‘type’) == ‘checkbox’ ) {
    if( $(e).attr(‘checked’) ) {
    r += escape($(e).attr(‘name’)) + ‘=’ + escape($(e).val()) + ‘&’;
    }
    }
    else {
    r += escape($(e).attr(‘name’)) + ‘=’ + escape($(e).val()) + ‘&’;
    }
    });

    return r;
    },

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.