本文介绍了AJAX提交jQuery通过多种形式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以假设我有3种形式

<form name="form1">
<input name="input"></input>
<submit></submit>
</form>

<form name="form2">
<input name="input"></input>
<submit></submit>
</form>

<form name="form3">
<input name="input"></input>
<submit></submit>
</form>

每个形式都有其自己的提交按钮

Each of the form has its own submit button

现在假设我有另一种形式

now suppose I have another form

<form id="submitAll">
<submit value="submit all"></submit>
</form>

其唯一的功能是同时提交所有其他3种形式....现在这里的约束:

whose sole function is to submit all the other 3 forms simultaneously....now here are the constraints:

    当submitAll提交
  1. ,它这样做,使用Ajax和转发来自所有其他3种形式的输入数据processor.php preferably通过POST
  2. processor.php需要能够区分哪些输入到哪个表格......,然后分别处理每个表格的输入
  1. when submitAll is submitted, it has to do so using Ajax and forward the input data from all the other 3 forms to processor.php preferably via POST
  2. processor.php needs to be able to distinguish between which inputs go to which form...and then process the inputs of each form separately

我的问题是....什么是使processor.php能够区分哪些输入属于最好的办法何种形式......

My question is....what is be the best way to make processor.php be able to distinguish which inputs belong to which form.....

我的previous尝试是使用jQuery的序列化到所有3种形式的投入序列,但它会全部投入合并成一个字符串,并注意到,因为在形式的输入具有相同的名称,字符串古话叫做输入=等等与放大器,输入=等等与放大器,输入=胡说,我无法区分哪个输入变为何种形式......

My previous attempts was to use jquery's serialize to serialize all the 3 forms' inputs, but then it would merge all the inputs into one string and notice that since the inputs in the forms have the same name, the string goes like "input=blah&input=blah&input=blah" and I can't distinguish between which input goes to which form.....

有高度preferable具有在形式输入到具有相同的名称,以便processor.php能够顺利执行

It is highly preferable to have the inputs in the forms to have the same name so that processor.php can execute smoothly

有没有去进行POST字符串传递作为数组或JSON或任何其他形式,使processor.php可以区分哪些输入不用使输入名称不同,以形成?请记住,它需要通过Ajax这样做

Is there away to make POST strings be passed as arrays or json or any other format so that processor.php can distinguish which input goes to which form without making the input names differ? remember it needs to do so via Ajax

在此先感谢!

推荐答案

喜欢

  • NAME =Form1的【输入】
  • NAME =窗体2【输入】
  • NAME =Form3【输入】

然后做定期的序列化和$。员额,这将帮助你保持相同的命名约定处理器循环

then do regular serialize and $.post, this will help you keep the same naming convention in processor loop

编辑:

<?php
foreach($_POST as $form) {
     // $form = array('input' => 'i am here')
     processForm($form); // names are still the same for all forms
}
?>

这篇关于AJAX提交jQuery通过多种形式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 12:06