<small id='yFNzu'></small><noframes id='yFNzu'>

  • <tfoot id='yFNzu'></tfoot>
    <legend id='yFNzu'><style id='yFNzu'><dir id='yFNzu'><q id='yFNzu'></q></dir></style></legend>
    • <bdo id='yFNzu'></bdo><ul id='yFNzu'></ul>
    <i id='yFNzu'><tr id='yFNzu'><dt id='yFNzu'><q id='yFNzu'><span id='yFNzu'><b id='yFNzu'><form id='yFNzu'><ins id='yFNzu'></ins><ul id='yFNzu'></ul><sub id='yFNzu'></sub></form><legend id='yFNzu'></legend><bdo id='yFNzu'><pre id='yFNzu'><center id='yFNzu'></center></pre></bdo></b><th id='yFNzu'></th></span></q></dt></tr></i><div id='yFNzu'><tfoot id='yFNzu'></tfoot><dl id='yFNzu'><fieldset id='yFNzu'></fieldset></dl></div>

      1. codeigniter - 依赖于 jquery 和 ajax post 的下拉列表

        时间:2023-10-03
        • <i id='UixFV'><tr id='UixFV'><dt id='UixFV'><q id='UixFV'><span id='UixFV'><b id='UixFV'><form id='UixFV'><ins id='UixFV'></ins><ul id='UixFV'></ul><sub id='UixFV'></sub></form><legend id='UixFV'></legend><bdo id='UixFV'><pre id='UixFV'><center id='UixFV'></center></pre></bdo></b><th id='UixFV'></th></span></q></dt></tr></i><div id='UixFV'><tfoot id='UixFV'></tfoot><dl id='UixFV'><fieldset id='UixFV'></fieldset></dl></div>
          <tfoot id='UixFV'></tfoot>

            <tbody id='UixFV'></tbody>

          <small id='UixFV'></small><noframes id='UixFV'>

            <legend id='UixFV'><style id='UixFV'><dir id='UixFV'><q id='UixFV'></q></dir></style></legend>

                • <bdo id='UixFV'></bdo><ul id='UixFV'></ul>

                • 本文介绍了codeigniter - 依赖于 jquery 和 ajax post 的下拉列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  视图:learning_view.php

                  view : learning_view.php

                  这是我从数据库中填充的第一个下拉列表.

                  Here is the first dropdown which I am populating from database.

                      <select name = 'category' id = 'category'>
                          <option value="">-- Select Category --</option>
                          <?php foreach($category as $item){ ?>
                          <option value="<?php echo $item->id_cat; ?>"><?php echo $item->name; ?></option>
                          <?php } ?>
                      </select>
                      <br><br>
                  

                  我想要的是填充另一个依赖于第一个下拉列表的下拉列表.为此,我使用了 jQuery ajax 帖子.

                  What I want is to populate another dropdown which is dependent on the first dropdown. For that I have used the jQuery ajax post.

                  第二个下拉列表:

                      <select name = 'type' id = 'type'>
                          <option value="">-- Select Type --</option>
                          <?php foreach($type as $item){ ?>
                          <option value="<?php echo $item->id_type; ?>"><?php echo $item->name; ?></option>
                          <?php } ?>
                      </select>
                      <br><br>
                  

                  ajax 帖子:

                      jQuery(document).ready(function(){
                        $("#category").change(function() {
                          var category_id = {"category_id" : $('#category').val()};
                          console.log(category_id);
                  
                          $.ajax({
                            type: "POST",
                            data: category_id,
                            url: "<?= base_url() ?>learning/dependent_dropdown",
                  
                            success: function(data){
                  
                              $.each(data, function(i, data){
                              console.log(data.name);
                              console.log(data.id_type)
                              });
                             }
                           });
                         });
                       });
                  

                  控制器:learning.php

                  controller : learning.php

                     public function dependent_dropdown()
                     {
                         if(isset($_POST['category_id']))
                         {
                             $this->output
                             ->set_content_type("application/json")
                             ->set_output(json_encode($this->learning_model->getType($_POST['category_id'])));
                         }
                     }
                  

                  数据来自我检查过的ajax帖子后的数据库

                  The data is coming from the database after ajax post which I checked by

                      console.log(data.name);
                      console.log(data.id_type)
                  

                  在控制台中.

                  但无法弄清楚如何使用我视图的第二个下拉列表中的数据.

                  But couldn't able to figure out how to use the data in the second dropdown of my view.

                  我的意思是如何使用我在 ajax 发布后收到的数据填充第二个下拉列表.

                  I mean how can i populate the second dropdown with the data i have received after ajax post.

                  推荐答案

                  我通过修改ajax帖子的success函数找到了解决我的问题的方法:

                  I found a solution to my problem by modifying the success function of the ajax post:

                  success: function(data) {
                      $.each(data, function(i, data) {
                          $('#type').append("<option value='" + data.id_type + "'>" + data.name + "</option>");
                      });
                  }
                  

                  将值附加到下拉列表中.

                  Which append the value into the drop down.

                  <select name="type" id="type">
                      <option value="">-- Select Type --</option>
                  </select>
                  

                  我只是在ajax帖子的success函数中给了select块的id,并附加了值.它可以工作,但有一个问题,即当我更改第一个下拉菜单的选择时会出现新值,但为上一个选择显示的值并没有消失.

                  I just gave the id of the select block into the success function of the ajax post and appended the value. It works but there is a problem which is when I change the selection of the first dropdown new value appears but the values which were showing for the previous selection doesn't go away.

                  这篇关于codeigniter - 依赖于 jquery 和 ajax post 的下拉列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:php下拉菜单填充 下一篇:OpenCart:下拉标题购物车信息的 div 在哪里?

                  相关文章

                  最新文章

                • <i id='aA8EE'><tr id='aA8EE'><dt id='aA8EE'><q id='aA8EE'><span id='aA8EE'><b id='aA8EE'><form id='aA8EE'><ins id='aA8EE'></ins><ul id='aA8EE'></ul><sub id='aA8EE'></sub></form><legend id='aA8EE'></legend><bdo id='aA8EE'><pre id='aA8EE'><center id='aA8EE'></center></pre></bdo></b><th id='aA8EE'></th></span></q></dt></tr></i><div id='aA8EE'><tfoot id='aA8EE'></tfoot><dl id='aA8EE'><fieldset id='aA8EE'></fieldset></dl></div>

                      <legend id='aA8EE'><style id='aA8EE'><dir id='aA8EE'><q id='aA8EE'></q></dir></style></legend>

                        <bdo id='aA8EE'></bdo><ul id='aA8EE'></ul>

                      <small id='aA8EE'></small><noframes id='aA8EE'>

                    1. <tfoot id='aA8EE'></tfoot>