简体   繁体   中英

Mootools iterate over form and grep values for xhr-request

Is it possible to get all values from a <form> and parse it to mootools/json, so that I can use it in an XHR-request like:

var req = new Request.HTML({
 method: 'post',
 url: 'xhr_request.php',
 data: {
  formdata:       $('inputform').getdata(),
  someotherdata:  'hello world'
 }
}).send();

At the moment I have only text-input fields. In the json I like to have the input-name or ID as the key for the value. eg:

<form id="inputform">    
<input type="text" id="name" name="name"/>
<input type="text" id="company" name="company"/>
</form>

//mootools script parsing above to this:

data: {
'name' : 'John Doe',
'company': 'Joeys LTD'
},

如果您将$('inputform')作为data:传递,它将自动工作data: -它将为您序列化。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM