0

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. e.g.:

<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'
},
4

1 回答 1

1

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

于 2013-05-16T09:55:53.747 回答