doufu8887 2018-03-01 09:55
浏览 35

成功功能不在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

  • 写回答

2条回答 默认 最新

  • duan0424 2018-03-01 10:03
    关注

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

    评论

报告相同问题?

悬赏问题

  • ¥15 RPA正常跑,cmd输入cookies跑不出来
  • ¥15 求帮我调试一下freefem代码
  • ¥15 matlab代码解决,怎么运行
  • ¥15 R语言Rstudio突然无法启动
  • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
  • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。