aonurdemir
12/22/2012 - 5:01 PM

This function extends jQuery by serializeObject method. Argument — form data, returns object.

This function extends jQuery by serializeObject method. Argument — form data, returns object.

;(function ($) {
    $.fn.serializeObject = function () {
        var obj = {},
            arr = this.serializeArray();

        $.each(arr, function () {
            if (typeof obj[this.name] !== "undefined") {
                if (!obj[this.name].push) {
                    obj[this.name] = [obj[this.name]];
                }
                obj[this.name].push(this.value || "");
            } else {
                obj[this.name] = this.value || "";
            }
        });

        return obj;
    };
}(jQuery || {}));