[英]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: 是否有可能从
<form>
获取所有值并将其解析为mootools / json,以便我可以在XHR请求中使用它,例如:
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.
在json中,我喜欢将输入名称或ID作为值的键。 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: //上面的mootools脚本解析:
data: {
'name' : 'John Doe',
'company': 'Joeys LTD'
},
如果您将$('inputform')
作为data:
传递,它将自动工作data:
-它将为您序列化。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.