Saturday, June 28, 2008

Form submit via jQuery

With jQuery it is easy to implement form submit by Ajax. This is how I do it:
$("#filter").submit(function(event) {
    event.preventDefault();
    event.stopPropagation();

    var params = {};
    $(":input", this).each(function() {
      params[this.name] = this.value;
    });

    $.get("/ajax/filter", params, aCallback);
});
A working example is the filter form on Jak√Ĺ Byt: Mapa.

No comments: