jQuery Ajaxify

by dom111 on August 11th, 2009

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.

2 Comments
  1. Andrea permalink

    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;
    },

    • D’oh! Well spotted! Thanks very much for the comment, I’ll update the script as soon as possible!

Leave a Reply

Note: XHTML is allowed. Your email address will never be published.

Subscribe to this comment feed via RSS