成功功能不在ajax中工作

I was getting alert value after change function but after success function, I not getting any values

my ajax page

$(document).ready(function(){
    $("#customer").change(function() {
        var customer_type = $(this).find(":selected").val();
        var dataString = 'customer_type='+ customer_type;
        $.ajax({
            url: 'http://localhost/capms_v3/ajax/getcust_type.php',
            dataType: "json",
            data: dataString,
            cache: false,
            success: function(customerData) {
                alert(data);
                alert("test");
                if(customerData) {
                    var customer = [customerData];
                    customerData.forEach(function(item) {
                        var data = '<tr>';
                        data+= '<td colspan="4"> </td>';
                        data+= '<td align="right">'+item.company_id+'</td>';
                        data+= '<td align="right">'+item.company_name+'</td>';
                        data+='</tr>';
                        $('.appendData').append(data);
                    });
                } else {
                    $("#heading").hide();
                    $("#records").hide();
                    $("#no_records").show();
                }
            }
        });
    });
}); 

my array values are not coming after the success function but in getcusttype page values was coming in an array

getcusttype.php

<?php 
     //header("Content-type:application/json");
       include 'db.php';
       $db=DbConnect();

   if($_REQUEST['customer_type']) {
     $sql = "SELECT company_id,company_name FROM ca_customer WHERE customer_type ='".$_REQUEST['customer_type']."'";
     $result = mysql_query($sql) or die(mysql_error());
     $data = array();
     while( $rows = mysql_fetch_array($result) ) {
     $data[] = $rows;
              }
              echo json_encode($data);
              } else {
              echo 0;
              }?>

  //var customer =[{"0":"1","company_id":"1","1":"Win Win 
  web","company_name":"Win Win web"},{"0":"7","company_id":"7","1":"New 
  Company","company_name":"New Company"},
  {"0":"10","company_id":"10","1":"Murugan Super 
  Store","company_name":"Murugan Super Store"}];

after the success: function(customerdata) if I alert(data) values was getting alert I don't know what error I have made.

view

<select id="customer" name="customer_type" class="form-control">
 <option value="">Select Customer Type</option>
  <?php 
     foreach($all_ca_customer_type as $ca_customer_type)
      {
    $selected = ($ca_customer_type['customer_type_id'] == $this->input->post('customer_type')) ? ' selected="selected"' : "";
    echo '<option value="'.$ca_customer_type['customer_type_id'].'" '.$selected.'>'.$ca_customer_type['customer_type_name'].'</option>';
                            } 
                            ?>
                        </select>
 <tbody class="appendData">
    </tbody>

not getting values after success function.if anybody face this problem help me.thanks in advance

Uncomment header("Content-type:application/json"); in getcusttype.php

It looks like your alert() function is referencing data Where does data come from? Try alert(customerData) in place of alert(data).

   success: function(customerData) {
        alert(data);
        alert("test");
        if(customerData) {
            var customer = [customerData];
            customerData.forEach(function(item) {
                var data = '<tr>';
                data+= '<td colspan="4"> </td>';
                data+= '<td align="right">'+item.company_id+'</td>';
                data+= '<td align="right">'+item.company_name+'</td>';
                data+='</tr>';
                $('.appendData').append(data);
            });
        } else {
            $("#heading").hide();
            $("#records").hide();
            $("#no_records").show();
        }
    }

If you're looking to alert the row that your appending you should move the alert(data) call, as is, down into your forEach() block after you declare your data variable. Ex:

customerData.forEach(function(item) {
    var data = '<tr>';
        data+= '<td colspan="4"> </td>';
        data+= '<td align="right">'+item.company_id+'</td>';
        data+= '<td align="right">'+item.company_name+'</td>';
        data+='</tr>';
    alert(data);
    $('.appendData').append(data);
});