backbone.js - jQuery .serializeArray() returns empty array -



backbone.js - jQuery .serializeArray() returns empty array -

this question has reply here:

serialize form not working in jquery 4 answers

i'm using jquery , backbone building app. rewrite project in amd architecture require.js.. starts problems posting forms. form:

*<div data-role="page" id="login" data-theme="a"> <form class="loginpageform"> <div data-role="content" style="padding: 15px"> <h3 id="login_heading"> login </h3> <div data-role="fieldcontain"> <fieldset data-role="controlgroup" id="email_fieldset"> <label for="email_textinput" > email </label> <input id="email_textinput" placeholder="john@doe.com" value="" type="text" /> </fieldset> </div> <div data-role="fieldcontain"> <fieldset data-role="controlgroup" id="password_fieldset"> <label for="password_textinput"> password </label> <input id="password_textinput" placeholder="secret password" value="" type="password" /> </fieldset> </div> <input type="submit" class="btn" value="login"/> <a data-role="button" data-transition="none" data-theme="f" href="#register" id="registerbutton">register</a> </div> </form> </div>*

and i'm using :

**$.fn.serializeobject = function(){ var arraydata, objectdata; arraydata = $(this).serializearray(); objectdata = {}; $.each(arraydata, function() { var value; if (this.value != null) { value = this.value; } else { value = ''; } if (objectdata[this.name] != null) { if (!objectdata[this.name].push) { objectdata[this.name] = [objectdata[this.name]]; } objectdata[this.name].push(value); } else { objectdata[this.name] = value; } }); homecoming objectdata; }**

for creating json.. problem line $(this).serializearray(); returns empty array: $(this).serializearray(): array[0] length: 0 proto: array[0]

my object "this" looks like:

arraydata: array[0] objectdata: undefined this: v.fn.v.init[1] 0: form.loginpageform 0: fieldset#email_fieldset 1: input#email_textinput 2: fieldset#password_fieldset 3: input#password_textinput 4: input.btn

do have thought how should avoid problem, form works before played amd architecture ?

your form elements doesn't have name attributes. when submit form elements' values posted server name key. name important.

according jquery serializearray docs

the .serializearray() method uses standard w3c rules successful controls determine elements should include; in particular element cannot disabled , must contain name attribute. no submit button value serialized since form not submitted using button. info file select elements not serialized.

jquery backbone.js requirejs amd

Comments

Popular posts from this blog

web services - java.lang.NoClassDefFoundError: Could not initialize class net.sf.cglib.proxy.Enhancer -

Accessing MATLAB's unicode strings from C -

javascript - mongodb won't find my schema method in nested container -