javascript - jQuery: serializing array returns empty string -


i did not forget add name attributes common problem , yet serialized form returning empty string. doing wrong?

html/javascript:

<head> <script src="http://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script> <script> $( document ).ready( function() {     $('#word_form').submit(function(e) {         e.preventdefault();         console.log($(this).serialize()); //returns empty string     }); }); </script> </head>  <body>     <div id="wrapper">         <form name="word_form" id="word_form" method="post">             <input type="image" name="thumbsup" id="thumb1" value="1" src="http://upload.wikimedia.org/wikipedia/commons/8/87/symbol_thumbs_up.svg" style="width:50px;height:50px;">             <input type="image" name="thumbsdown" id="thumb2" value="2" src="http://upload.wikimedia.org/wikipedia/commons/8/84/symbol_thumbs_down.svg" style="width:50px;height:50px;">         </form>     </div> </body> 

dont know if better way, write own plugin this, like:

(function($) {      $.fn.serializeall = function() {          var toreturn    = [];         var els         = $(this).find(':input').get();             console.log("elements:" + els);         $.each(els, function() {             if (this.name && !this.disabled && (this.checked || /select|textarea/i.test(this.nodename) || /text|hidden|password/i.test(this.type) || this.src)) {                 var val = $(this).val();                 toreturn.push( encodeuricomponent(this.name) + "=" + encodeuricomponent( val ) );             }         });          return toreturn.join("&").replace(/%20/g, "+");         }  })(jquery); //and use var serialized = $('#word_form').serializeall(); console.log(serialized); 

demo jsfiddle


Comments

Popular posts from this blog

database - VFP Grid + SQL server 2008 - grid not showing correctly -

jquery - Set jPicker field to empty value -

.htaccess - htaccess convert request to clean url and add slash at the end of the url -