jquery post在firebug中未定义

时间:2011-07-18 19:38:38

标签: javascript jquery

在表格中的2个元素中,我在firebug中收到'undefined'。我试图追踪错误,但一直打砖墙,因此发布。其中一个错误区域位于divId块中,另一个区域是表单中的#company。如果有人能检查我的代码并指出我的错误,我将不胜感激。感谢

// Function to add box

function addbox() {

    $("#boxform").dialog({
        autoOpen: false,
        resizable: true,
        modal: true,
        title: 'Submit a box intake request',
        width: 470,
        beforeclose: function (event, ui) {
            $("#addbox").html("");
            $("#divId").html("");

        }

    });

    $('#boxsubmit').click(function () {

        var company = $('.company').val();
        var box = $('.box').val();
        var service = $('#service').val();
        var authorised = $('.authorised').val();
        var address = $('.address').val();
        var data = 'company=' + company + '&box=' + box + '&authorised=' + authorised + '&service=' + service + '&address=' + address;
        $.ajax({
            type: "POST",
            url: "boxesadd.php",
            data: data,
            success: function (data) {
                $("#boxform").get(0).reset();
                $('#addbox').html(data);
                //$("#form").dialog('close');
                $("#flex1").flexReload();

            }
        });
        return false;

    });

    $("#boxform").dialog('open');

}

HTML

<script language="javascript" type="text/javascript">
      $(function() {
    $("#company").live('change', function() { if ($(this).val()!="")
    $.get("../../getOptions.php?customer=" + $(this).val(), function(data) {
    $("#divId").html(data); }); }); 
      });
</script

<form id="boxform" method="post" class="webform" name="boxform" />

        <label for="company">Select a Company:</label>
        <select name="company" id="company" />
          <option SELECTED VALUE="">Select a Company</option>
          <?php
           do {  
           ?>
          <option value="<?php echo $row_Recordsetcust['customer']?>"><?php echo $row_Recordsetcust['customer']?></option>
          <?php

          } 
          while ($row_Recordsetcust = mysql_fetch_assoc($Recordsetcust));
          $rows = mysql_num_rows($Recordsetcust);
          if($rows > 0)

         {
          mysql_data_seek($Recordsetcust, 0);
          $row_Recordsetcust = mysql_fetch_assoc($Recordsetcust);
                    }

          ?>
          </select>

          <!--- displays the address from the change function -->
          <div id="divId"></div>

3 个答案:

答案 0 :(得分:4)

尝试更改

<form id="boxform" method="post" class="webform" name="boxform" />

<form id="boxform" method="post" class="webform" name="boxform"> 

<select name="company" id="company" />

<select name="company" id="company">

var company = $('.company').val();

var company = $('#company').val();

答案 1 :(得分:1)

<select name="company" id="company" />应为<select name="company" id="company"> 然后表格标签也没有正确关闭。

答案 2 :(得分:1)

#boxsubmit click处理程序中,您使用点而不是#company的哈希值。

更改

    var company = $('.company').val();

    var company = $('#company').val();

并删除非空元素上的自关/