简体   繁体   English

依赖的下拉错误未定义的索引:TRANCHE codeigniter

[英]dependent dropdown error Undefined index: TRANCHE codeigniter

i have this drop-down dependent on the choices of the other 2 drop-downs i have debugged the java script but it has an error on my error logs that says, 我有这个下拉菜单,取决于我调试了Java脚本的其他2个下拉菜单的选择,但是我的错误日志中有一个错误,说:

Undefined index: TRANCHE

here is my controller 这是我的控制器

   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)));
       }
   }

and here is my javascript 这是我的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>");
          });
      }
     });
   });
 });

please tell me the problem and how can i debug it. 请告诉我这个问题以及如何调试。 thanks 谢谢

You have to make an array to send both values. 您必须制作一个数组来发送两个值。

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>");
      });
  }
 });

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM