View Single Post
Eski 08/09/2007, 21:28   #4 (permalink)
e-zeus
Lorem ipsum dolor...
 
e-zeus Adlı Üyenin Profil Grafiği
 
Üyelik Tarihi: 02/2007
Yer: Ankara
Mesaj: 229
Tamam Buldummm

Arkadaşlar bir plug-in buldum. Küçük bir şey. Prototype ile aynı işlevi gerçekleştiriyor:


Kullanımı:


To retrieve a hash of key/value pairs, just call the plugin on any jQuery form object:
Kod:
var params = $('#myForm').fastSerialize();
This hash can be used in jQuery's AJAX methods, e.g.:
Kod:
$.post('/path/to/script', $('#myForm').fastSerialize());
For a URL-ready string, pass the plugin's resultant hash to jQuery's param function:
Kod:
var params = $('#myForm').fastSerialize();
var fragment = $.param( params );


Plug-in kaynak kodu:


Kod:
$.fn.fastSerialize = function() {
    var a = [];
    $('input,textarea,select,button', this).each(function() {
        var n = this.name;
        var t = this.type;
        if ( !n || this.disabled || t == 'reset' ||
            (t == 'checkbox' || t == 'radio') && !this.checked ||
            (t == 'submit' || t == 'image' || t == 'button') && this.form.clicked != this ||
            this.tagName.toLowerCase() == 'select' && this.selectedIndex == -1)
            return;
        if (t == 'image' && this.form.clicked_x)
            return a.push(
                {name: n+'_x', value: this.form.clicked_x},
                {name: n+'_y', value: this.form.clicked_y}
            );
        if (t == 'select-multiple') {
            $('option:selected', this).each( function() {
                a.push({name: n, value: this.value});
            });
            return;
        }
        a.push({name: n, value: this.value});
    });
    return a;
};
e-zeus hatta değil   Alıntı Yaparak Yanıtla