jquery选择更改事件而不是发布表单数据

时间:2013-06-25 16:47:40

标签: php jquery ajax

当用户选择正确的公司时,我正在使用jquery更改事件来填充下拉菜单。换句话说,它用数据填充第二个菜单。虽然这工作正常,但当我发布表单并使用序列化捕获数据时,帖子中没有公司或地址详细信息。只是选项价值。在这种情况下'地址'。我如何编码以便我可以收集使用此方法发布的数据。感谢

jquery代码

$(function() {

        $("#BA_customer").live('change', function() { 
            if($(this).val()!="")
            $.get("/domain/admin/getDept.php?BA_customer=" + $(this).val(), function(data) {
            $("#BA_dept").html(data).show(); 
            });
            $.get("/domain/admin/getOptions.php?BA_customer=" + $(this).val(), function(data) {
            $("#BA_address").html(data).show(); 
            });

        }); 
          }); 


$(function(){         
        $("#BA_boxform").submit(function(){

         var formdata = $('#BA_boxform').serialize();
         //alert(formdata);
         $.ajax({
           type: "POST",
           url: "/domain/admin/requests/boxes/boxesadd.php",
           data: formdata,
           dataType: 'json',
           success: function(msg){
               //$("#confirm_department").hide();

               /*
               var $dialog = $('<div id="dialog"></div>')
               .html('Your intake was successfully submitted and will be viewable in the reporting area.<br /><br />Thank you.');
               $dialog.dialog({
               autoOpen: true,
               modal: true,
               title: 'Box intake submission successfull',
               width: 400,
               height: 200,
               draggable: false,
               resizable: false,
               buttons: {
               Close: function() {
               $( this ).dialog( "close" );
               }
               }
               });
               */
               //alert('You have succesfully submitted your ' + msg.company + ' report. Thank you.');
               //console.log(msg);
               //$("#BA_addbox").html("You may now close this window.");

               //$("#formImage .col_1 li").show();
               $("#BA_boxform").get(0).reset();
               $("#boxaddform").hide();
          }
       });
         return false;
     });
});

// End function to submit box intake form

getOptions.php代码

      echo '<label for="address">Address:</label>'.'<br />'.'<select name="customeraddress">';
      echo '<option value="">Select delivery address</option>';
      while ($row_rs_select_address2 = mysql_fetch_assoc($rs_select_address2))
      {
      $address=$row_rs_select_address2['address1_com']. "".
      $row_rs_select_address2['address2_com']. "".
      $row_rs_select_address2['address3_com']. " ".
      $row_rs_select_address2['town_com']. " ".
      $row_rs_select_address2['postcode_com'];
      echo '<option value="address">'.$address.'</option>';
      }
      echo '</select>';

1 个答案:

答案 0 :(得分:4)

在这里,您需要为循环的每次迭代将选项值硬编码为address

echo '<option value="address">'.$address.'</option>';

这意味着无论选择哪个地址,服务器端都只会看到&#34;地址&#34;。相反,您应该将地址ID插入值中。

echo '<option value="' . (int)$row_rs_select_address2['address_id'] . '">'.$address.'</option>';
// assuming the ID is in $row_rs_select_address2['address_id']