dependent dropdown error未定义的索引:TRANCHE codeigniter

时间:2016-07-04 14:07:44

标签: javascript php ajax codeigniter

我有这个下拉列表取决于我已调试java脚本的其他2个下拉列表的选择但是我的错误日志上有错误说明,

Undefined index: TRANCHE

这是我的控制器

   public function dependent_dropdown()
   {
       if(isset($_POST['TRANCHE']) || isset($_POST['GRADE']))
       {

            $data = $_POST['TRANCHE'];
            $data1 = $_POST['GRADE'];
            $this->output
            ->set_content_type("application/json")
            ->set_output(json_encode($this->EmployeeSalary_Model->getType($data, $data1)));
       }
   }

这是我的javascript

jQuery(document).ready(function(){
  $("#GRADE").change(function() {
    var TRANCHE = {"TRANCHE" : $('#TRANCHE').val()};
    var GRADE = {"GRADE" : $('#GRADE').val()};
    console.log(TRANCHE);
    console.log(GRADE);

    $.ajax({
      type: "POST",
      data: (TRANCHE, GRADE),
      url: "<?php base_url(); ?>EmployeeSalary/dependent_dropdown/",

      success: function(data){
          var select = $('#SAL_ID');
          select.html('');
          $.each(data, function(i, option){
              select.append("<option value='"+option.ID+"'>"+option.AMOUNT+"</option>");
          });
      }
     });
   });
 });

请告诉我问题以及如何调试它。感谢

1 个答案:

答案 0 :(得分:0)

你必须创建一个数组来发送两个值。

var postData = [ TRANCHE , GRADE ]

$.ajax({
  type: "POST",
  data: JSON.stringify(postData), ////stringify is important 
  url: "<?php base_url(); ?>EmployeeSalary/dependent_dropdown/",

  success: function(data){
      var select = $('#SAL_ID');
      select.html('');
      $.each(data, function(i, option){
          select.append("<option value='"+option.ID+"'>"+option.AMOUNT+"</option>");
      });
  }
 });