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?
我有几个隐藏的输入字段用于保存由javascript计算的坐标。这些字段的目的是在提交表单时传递坐标。我通过MooTools使用AJAX请求。有没有一种简单的方法来消除隐藏的输入字段并将它们附加到通过表单发送的$ _POST数据?
2 个解决方案
#1
1
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]")
.
新请求({data:$(“formid”)})。send();将序列化表单并发送所有表单域。您可以做的是在提交之前将隐藏字段移动到表单中,这样它也将包括它们(通过$(“formid”)。采用(el1,el2,... eln);其中els是你的隐藏 - 或者收藏你做过像$$(“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.
如果你手动编写数据对象,那么只需用一个键将它们添加到它,它只是一个key-> value对的哈希表。
#2
0
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.
我不使用MooTools,但我对Prototype,jQuery和原始Javascript模式的体验是,基于Javascript的POST是使用动态创建的
What's the reason you don't want to use hidden input fields? Does the job for me...
你不想使用隐藏输入字段的原因是什么?这份工作对我来说......
#1
1
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]")
.
新请求({data:$(“formid”)})。send();将序列化表单并发送所有表单域。您可以做的是在提交之前将隐藏字段移动到表单中,这样它也将包括它们(通过$(“formid”)。采用(el1,el2,... eln);其中els是你的隐藏 - 或者收藏你做过像$$(“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.
如果你手动编写数据对象,那么只需用一个键将它们添加到它,它只是一个key-> value对的哈希表。
#2
0
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.
我不使用MooTools,但我对Prototype,jQuery和原始Javascript模式的体验是,基于Javascript的POST是使用动态创建的
What's the reason you don't want to use hidden input fields? Does the job for me...
你不想使用隐藏输入字段的原因是什么?这份工作对我来说......