如何每个序列化? [英] how to each serialize?

查看:59
本文介绍了如何每个序列化?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个问题,我有一个包含多个表格的字段,这些表格最多可以重复50次,但是具有不同的值,我想用$发送从列表中选择的表格. post('process.php',$(#form").serialize(),function(data),但是当单击表单值时,仅发送第一个表单,但不发送要选择的表单值.

I have a problem, I have a field with several forms, these forms can get to repeat up to 50 times but with different values​​, I want to send the form you select from the list with $. post ('process.php', $ ("# form") . serialize (), function (data), but when clicking on a form values ​​are sent only the first form but not send form values ​​to select.

尝试单位本身,它们就是两个简单的文档

try units themselves, those are two simple documents such

forms.html

<html>
<head>
<title>Ejemplo de form con jquery</title> 
<script type="text/javascript" src="http://code.jquery.com/jquery-1.4.2.min.js"></script>
<script type="text/javascript" src="http://ajax.microsoft.com/ajax/jquery.validate/1.7/jquery.validate.min.js"></script>
<script type="text/javascript">
$(function() {
$("form").validate( {
submitHandler: function(form) {
$.post('process.php', $(form).serialize(), function(data) {
$('#results').html(data);
            });
        }
    });
});
</script>
</head>
<body>
<form method="post" id="form">
    <label for="name" id="name_label">Nombre</label>  
    <input type="text" name="name" id="name" size="30" value=""/>  
    <br>

    <input type="submit" name="submit" value="SEND"> 
</form>

<form method="post" id="form">
    <label for="name" id="name_label">Nombre</label>  
    <input type="text" name="name" id="name" size="30" value=""/>  
    <br>
  <input type="submit" name="submit" value="SEND"> 
</form>

<form method="post" id="form">
    <label for="name" id="name_label">Nombre</label>  
    <input type="text" name="name" id="name" size="30" value=""/>  
    <br>
  <input type="submit" name="submit" value="SEND"> 
</form>

<form method="post" id="form">
    <label for="name" id="name_label">Nombre</label>  
    <input type="text" name="name" id="name" size="30" value=""/>  
    <br>
  <input type="submit" name="submit" value="SEND"> 
</form>

<form method="post" id="form">
    <label for="name" id="name_label">Nombre</label>  
    <input type="text" name="name" id="name" size="30" value=""/>  
    <br>
  <input type="submit" name="submit" value="SEND"> 
</form>
<div id="results"></div>
</body>
</html>

process.php

 <?php

    print "Form enviado correctamente: <br>the post value is <b>".$_POST['name']."</b> ";
?>

我想要的是,如果我在下面的最后一个表单中添加一个值,然后我将向您发送此表单或您选择的任何表单的值,而不是上面存在问题所在的表单的值发送给您不想q一次发送所有表单的值ls只是想发送要选择的表单的值

all I want is that if I put a value to the last form below and I will send you send the value of this form or any you choose, not the value of the form above that there is where the problem is and do not want q send the value of all forms at once ls just want to send the value of the form to select

推荐答案

submitHandler函数接收作为其参数提交的表单,因此您可以执行以下操作:

The submitHandler function receives the form being submitted as its argument, so you can do:

  $(function() {
      $("form").each(function() {
          $(this).validate( {
              submitHandler: function(formbeingsubmitted) {
                  $.post('process.php', $(formbeingsubmitted).serialize(), function(data) {
                      $('#results').html(data);
                  });
              }
          });
      });
  });

显然,当将jquery-validate插件应用于jQuery集合时,它无法正常工作.因此有必要使用.each()分别初始化它们.

Apparently the jquery-validate plugin does not work properly when applied to a jQuery collection. So it's necessary to use .each() to initialize each of them separately.

这篇关于如何每个序列化?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆