dongshan2004 2015-12-03 03:32
浏览 62
已采纳

从Dropbox到另一个Dropbox更改值的AJAX

I have select html tag, which value get from database, and the data will return to query and return an value to another dropbox.

My tag HTML like this: enter image description here

And i want to give the value of data which is selected to another dropdown here:

enter image description here

And my javascript like this:

enter image description here

And the url direct to here:

enter image description here

And the model like this : enter image description here

How i can change value to id sektor 20, when i have selecting a dropdown from sektor10?, and how to return value from controller and change value of sektor20?

  • 写回答

1条回答 默认 最新

  • drnpwmq4536 2015-12-03 04:16
    关注

    A working sample what I have done for selecting from dropdown and display values as per the selected value.

    In your controller-

    function functionname($id){
    
        $details =  $this->your_model->get_details($id);
        echo  json_encode($details);
        exit;
    
    }
    

    In Model-

    function get_details($id){
    
      $this->db->select('*');
      $this->db->from('packages'); 
      $this->db->where('package_id',$id); 
      $query = $this->db->get()->result();
      return $query;
    }
    

    Javascript-

    <script src="http://code.jquery.com/jquery-1.11.0.min.js"></script>
    <script  src="http://code.jquery.com/jquery-latest.min.js"></script>
    <script type="text/javascript" language="javascript">
    $(document).ready(function(){
    
        $("#sector10").change(function() {
     var selectedMark = $("#sector10").val();
    if (selectedMark != "") {
        jQuery.ajax({
           type: 'POST',
          dataType: "json",
           async:false,
            url: "<?php echo base_url() . 'loyalty/functionname/'; ?>" + selectedMark,
           success: function(data)
           {
                $("#cards").html("");
                $("#cards").append("<option value=''>Select a Card</option>");
                var index=1;
    
                $.each(data, function() {
                    $("#cards").append("<option value='" + this.card_id + "'>" + this.card_name + "</option>");
                    $("div#cards_chosen div.chosen-drop ul.chosen-results").append("<li class='active-result' data-option-array-index='"+index+"' >" + this.card_name + "</li>");
                    index++;
                });
           }
        });
    }
    });
    
    
    });
    </script>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 vscode的问题提问
  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类
  • ¥15 微带串馈天线阵列每个阵元宽度计算
  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM