我要的是填充另一个下拉这取决于第一个下拉。对于我已经使用了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 post:
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']))); } }
将数据从阿贾克斯后门柱的数据库,我检查
The data is coming from the database after ajax post which I checked by
console.log(data.name); console.log(data.id_type)
在控制台中。
in the console.
但不能能弄清楚如何使用数据在我看来,第二个下拉。
But couldn't able to figure out how to use the data in the second dropdown of my view.
我的意思是我怎么能填充第二个下拉与我阿贾克斯后门柱已经接收到的数据。
I mean how can i populate the second dropdown with the data i have received after ajax post.
我找到了解决我的问题,通过修改的AJAX后成功函数
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>
我只是给了选择块的ID进入的AJAX后取得成功的功能和附加价值。它的工作原理,但有一个问题,就是当我改变了一个下拉新的价值选择出现,但它被显示为previous选择的值不会消失。
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.
相关推荐
永昌府(2023最新永昌府百科介绍)
乐玉成(国家广播电视总局副局长)
哈立德·本·阿卜杜勒-阿齐兹(2023最新哈立德·本·阿卜杜勒-阿齐
2021世茂港珠澳口岸城·胡润全球富豪榜
3818库画廊(3818库画廊)
图尔沃(图尔沃)
各寨村(各寨村)
Android的 - 自定义AlertDialog背景颜色自定义、颜色、背景、Andr
找到一个点,使得在一组点P至任何点的最大距离为最小最小、距离、最
如何测试是否光标是空的SQLiteDatabase查询光标、测试、SQLiteDat
.NET ObservableDictionaryNET、ObservableDictionary
学习廉洁从教心得体会_学习廉洁从教心得体会
武侠群英传2攻略_1. 常规操作技巧
黑麦小猪豆沙包的做法_小猪豆沙包的做法
防止衰老这个方法早被公认了_女人防止衰老的方法有哪些?
肾病有什么症状_肾病的早期症状有哪些?
针灸治面瘫的效果怎么样_艾叶泡脚治面瘫的效果好吗
进补季节最养男人的6类食物_大蒜韭菜堪称“男人菜” 5类食物最“
跑步会瘦么有什么好办法_在平时坚持跑步能瘦身吗?
干眼症预防方法有什么_干眼症的预防方法有哪些
最新文章
朝阳乡(黑龙江省哈尔滨市香坊区辖乡)
劳动卫生与环境卫生学(2023最新劳动卫生与环境卫生学百科介绍)
亨利·克莱(2023最新亨利·克莱百科介绍)
吴以岭(以岭药业创始人)
卡罗尔巴茨
冯丹龙(辉瑞制药中国企业事务部总监)
为什么我不能运行我的SYSTEM32 exe文件?我的、文件、exe
新奇巧的URI不以Intent.ACTION_VIEW回应奇巧、不以、ACTION_VIEW
找不到总成找不到、总成
的.htaccess重写URL不起作用重写、不起作用、htaccess、URL
感动中国2015十大人物有哪些_感动中国十大人物有哪些
复印机如何扫描文件_复印机如何扫描文件
弯腰后直不起来怎么办_子宫后位的运动纠正方法
紫菜汤在家里天天喝有坏处吗?_天天喝咖啡有什么坏处呢
皮肤暗黄偏黑要怎么办_皮肤暗黄怎么调理能变白?
这样的卧室最伤心脏中招了吗_住房风水八禁忌你家中招了吗
深蹲是什么呢_深蹲是减哪里的赘肉
嗳气放屁是怎么回事?_两个月宝宝放屁臭怎么回事
便秘吃什么水果?吃这些最好_我最喜欢吃的水果吃起来该注意什么
一根玉米能防多种癌_虾仁玉米的做法多种做法的介绍