选择由jquery加载的<options>而不是序列化</options>

时间:2013-09-08 08:11:10

标签: php ajax forms jquery

我已加载表单。在表单中有一个选择区域,当更改时调用ajax查询来加载并显示第二级选择区域

$('.subjectareaid').change (function ()
     {
      var selected = $(this);
      var ssindex = selected.closest("tr").index()+1;
      var putid = '#subsub'+ssindex;
      var pdata = 'subjectareaid='+selected.val();
      $.ajax({
         type   : "POST",
         cache  : false,
         url    : "a_subsubject.php",
         data   : pdata,
         success: function(data) {
          $(putid).html(data);
          $(putid).removeClass('hideme');
         }
      });
     });

a_subsubject.php文件创建一个要返回的选项列表

 <option value=".$row['subsubjectid']."> ".$row['subsubjectname']

修改的HTML是一个表,表中是行。该行看起来像:

$outline .= "<tr><td>".$oline."Question ".$k."</td><td valign=bottom><select name=dif[".$j."]>".$difsel."</select></td><td valign=bottom><select class=subjectareaid name=sub[".$j."]>".$subsel."</select></td><td valign=bottom><select class=hideme id=subsub".$j." value=subsub[".$j."]><option value=0></select></td></tr>";

其中$ oline是空白或部分名称,$ k是问题编号,$ j是索引(1-54),$ difsel是select语句的选项,$ subsel是select语句选项,第三个是选择设置为单个选项,并使用hideme类隐藏。此外,它还有一个ID,允许它使用a_subsubject.php ajax调用返回的选项重新填充HTML。

所有这些表格都以表格

包装
 <form id=deform1>

提交表单后,将运行以下jquery:

     var formser =  $('#deform1').serialize();
     var crud = "&crud=scd";
     var scorecardid = '&scorecardid='+ escape($('input[name=id]').val());
     var pdata = formser+'&action=cru'+crud+scorecardid;

然后将其发送到ajax例程,pdata是传递给CRUD程序的数据以更新数据库。

在问题1,21和39的所有三个选择值中进行选择的结果(从警报中显示)是:{id = 1是接收代码在捕获和发送时忽略的隐藏字段作为后期在帖子字符串中的记分卡}

ID = 1&安培; DIF%5B1%5D = 0&安培;子%5B1%5D = 2及DIF%5B2%5D = 0&安培;子%5B2%5D = 0&安培; DIF%5B3%5D = 0&安培;子%5B3 %5D = 0&安培; DIF%5B4%5D = 0&安培;子%5B4%5D = 0&安培; DIF%5B5%5D = 0&安培;子%5B5%5D = 0&安培; DIF%5B6%5D = 0&安培;子%5B6%5D = 0&安培; DIF%5B7%5D = 0&安培;子%5B7%5D = 0&安培; DIF%5B8%5D = 0&安培;子%5B8%5D = 0&安培; DIF%5B9%5D = 0&安培;子%5B9%5D = 0&安培; DIF%5B10%5D = 0&安培;子%5B10%5D = 0&安培; DIF%5B11%5D = 0&安培;子%5B11%5D = 0&安培; DIF%5B12%5D = 0&安培;子%5B12%5D = 0&安培; DIF %5B13%5D = 0&安培;子%5B13%5D = 0&安培; DIF%5B14%5D = 0&安培;子%5B14%5D = 0&安培; DIF%5B15%5D = 0&安培;子%5B15%5D = 0&安培; DIF%5B16 %5D = 0&安培;子%5B16%5D = 0&安培; DIF%5B17%5D = 0&安培;子%5B17%5D = 0&安培; DIF%5B18%5D = 0&安培;子%5B18%5D = 0&安培; DIF%5B19%5D = 0&安培;子%5B19%5D = 0&安培; DIF%5B20%5D = 0&安培;子%5B20%5D = 0&安培; DIF%5B21%5D = 3及子%5B21%5D = 4和; DIF%5B22%5D = 0&安培;子%5B22%5D = 0&安培; DIF%5B23%5D = 0&安培;子%5B23%5D = 0&安培; DIF%5B24%5D = 0&安培;子%5B24%5D = 0&安培; DIF%5B25%5D = 0&安培;分%5B25%5D = 0&安培; DIF%5B26%5D = 0&安培;子%5B26%5D = 0&安培; DIF%5B27%5D = 0&安培;子%5B27%5D = 0&安培; DIF%5B28%5D = 0&安培;子%5B28 %5D = 0&是磷; DIF%5B29%5D = 0&安培;子%5B29%5D = 0&安培; DIF%5B30%5D = 0&安培;子%5B30%5D = 0&安培; DIF%5B31%5D = 0&安培;子%5B31%5D = 0&安培; DIF%5B32%5D = 0&安培;子%5B32%5D = 0&安培; DIF%5B33%5D = 0&安培;子%5B33%5D = 0&安培; DIF%5B34%5D = 0&安培;子%5B34%5D = 0&安培; DIF% 5B35%5D = 0&安培;子%5B35%5D = 0&安培; DIF%5B36%5D = 0&安培;子%5B36%5D = 0&安培; DIF%5B37%5D = 0&安培;子%5B37%5D = 0&安培; DIF%5B38% 5D = 0&安培;子%5B38%5D = 0&安培; DIF%5B39%5D = 2及子%5B39%5D = 3及DIF%5B40%5D = 0&安培;子%5B40%5D = 0&安培; DIF%5B41%5D = 0安培;子%5B41%5D = 0&安培; DIF%5B42%5D = 0&安培;子%5B42%5D = 0&安培; DIF%5B43%5D = 0&安培;子%5B43%5D = 0&安培; DIF%5B44%5D = 0&安培;子%5B44%5D = 0&安培; DIF%5B45%5D = 0&安培;子%5B45%5D = 0&安培; DIF%5B46%5D = 0&安培;子%5B46%5D = 0&安培; DIF%5B47%5D = 0&安培;子% 5B47%5D = 0&安培; DIF%5B48%5D = 0&安培;子%5B48%5D = 0&安培; DIF%5B49%5D = 0&安培;子%5B49%5D = 0&安培; DIF%5B50%5D = 0&安培;子%5B50% 5D = 0&安培; DIF%5B51%5D = 0&安培;子%5B51%5D = 0&安培; DIF%5B52%5D = 0&安培;子%5B52%5D = 0&安培; DIF%5B53%5D = 0&安培;子%5B53%5D = 0安培; DIF%5B54%5D = 0&安培;子%5B54%5D = 0&安培;行动= CRU&安培;污物= SCD&安培; scorecardid = 1

你可以看到dif%5B1%5D = 0&amp; sub%5B1%5D = 2&amp; dif%5B2%5D = 0&amp; sub%5B2%5D = 0这表明sub [1]已被设置为2这导致subsub1加载了一组选择选项然后显示。选择选项(第二项)但是表单数据的序列化没有捕获子列[1]。 [这也是记录21和记录39]。

在使序列化捕获第三个jquery添加的选择值之前,我是否遗漏了一些“更新”表单的方法?

1 个答案:

答案 0 :(得分:0)

好吧,代码是一行300行,另一行400行......

 $outline .= "<tr><td>".$oline."Question ".$k."</td><td valign=bottom><select name=dif[".$j."]>".$difsel."</select></td><td valign=bottom><select class=subjectareaid name=sub[".$j."]>".$subsel."</select></td><td valign=bottom><select class=hideme id=subsub".$j." value=subsub[".$j."]><option value=0></select></td></tr>";

看起来很好,但是这一行代码中有一个错误。

<td valign=bottom><select class=hideme id=subsub".$j." value=subsub[".$j."]><option value=0></select>

select语句没有“value”,它们有“name”。

浪费了25个小时的时间来追逐一个糟糕的HTML行。好的,我觉得很愚蠢。很难相信我在1997年为Prentice Hall写了一本关于CGI编程的血腥书。我很高兴我现在使用的是anon handle而不是我自己的名字。 : - )