消除对隐藏输入字段的需要
我有几个隐藏的输入字段,用于保存由 javascript 计算的坐标。这些字段的目的是在提交表单时传递坐标。我正在通过 MooTools 使用 AJAX 请求。有没有一种简单的方法可以消除隐藏的输入字段并将它们附加到通过表单发送的 $_POST 数据中?
I have several hidden input fields used to hold coordinates calculated by javascript. The purpose of these fields is to pass the coordinates when the form is submitted. I am using an AJAX request through MooTools. Is there a simple way to eliminate the hidden input fields and append them to the $_POST data being sent through the form?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
是的。很大程度上取决于表单数据的定义方式/发送方式。例如:
new Request({ data: $("formid") }).send();
将序列化表单并发送所有表单字段。您可以做的就是在提交之前将隐藏字段移动到表单中,以便它也包含它们(通过$("formid").adopt(el1, el2, ... eln);
其中 els是你的隐藏对象 - 或者你已经完成的集合,例如$$("input[type=hidden]")
如果你手动组成数据对象,然后只需使用键将它们添加到其中,它就可以了。 key->value 的哈希表对。
yes. if very much depends on the way your form data is defined / how it is sent. for example:
new Request({ data: $("formid") }).send();
will serialise the form and send all form fields through. what you can do is move the hidden fields into the form before submit so it will include them also (via$("formid").adopt(el1, el2, ... eln);
where els are your hiddens - or a collection you have done like$$("input[type=hidden]")
.if you compose the data object manually then just add them to it with a key, its just a hash table of key->value pairs.
我不使用 MooTools,但我对 Prototype、jQuery 和原始 Javascript 模式的经验是,基于 Javascript 的 POST 是通过
您不想使用隐藏输入字段的原因是什么?这份工作适合我吗...
I don't use MooTools, but my experience with Prototype, jQuery, and raw Javascript patterns is that Javascript-based POSTs are done with a <form> element created on the fly. Appending POST data is done by adding hidden input fields to that form element, and then the form is submitted.
What's the reason you don't want to use hidden input fields? Does the job for me...