JQuery.serializeArray () returns an empty array

I use jQuery and the spine to build my application. I recently rewrote a project in AMD architecture with require.js .. Then problems with publishing forms start up. This is my 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 use:

  **$.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; } }); return objectData; }** 

to create json. The problem is the line $ (this) .serializeArray (); which returns an empty array: $ (this) .serializeArray (): Array [0] length: 0 Proto : array [0]

My "this" object looks like this:

 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 you have an idea how can I avoid this problem, does this form work before I played with AMD architecture?

+4
source share
1 answer

Elements of your form do not have name attributes. When you submit the form, the values โ€‹โ€‹of the elements are sent to the server with their name as the key. Therefore, the name is important.

According to jQuery serializeArray Docs

The .serializeArray () method uses standard W3C rules for successful control to determine which elements it should include; in particular, an element cannot be disabled and must contain a name attribute. The submit button value is not serialized because the form was not submitted using the button. Data from file selection items is not serialized.

+13
source

All Articles