gpt4 book ai didi

javascript - 从 Combo Cox( View )获取值并发送到 Controller 而不加载页面

转载 作者:行者123 更新时间:2023-11-28 05:10:08 25 4
gpt4 key购买 nike

如何在不加载页面的情况下从 View 的代码点火器获取值到 Controller 。
我在 Controller 中有2个类,indexcreate_data
我需要动态打印 $test
我怎样才能让我的代码工作?

View

<?php echo form_open("example/create_data", "class='form-horizontal' row-border")?>

<select name="example" onchange()="this.form.submit()">
<option value="1">1</option>
<option value="2">2</option>
</select>
<button type="submit">Tambah</button>
<?php form_close()?>

Controller

function index(){
$data['combo'] = comboData();
$test = $this->input->post();
$data['test'] = $test;
echo $test;
if ($test==1) {
doSomething();
} else{
doNothing();
}
$this->template->display('example/index',$data);
}

最佳答案

||查看

<?php echo form_open("example/create_data", "class='form-horizontal' row-border")?>

<select name="example" onchange="change_option()">
<option value="1">1</option>
<option value="2">2</option>
</select>
<select id="your_second_dropdown_id_name">
<option value="0">no data</option>
</select>
<button type="submit">Tambah</button>
<?php form_close()?>

||javascript/jquery

var category_id =  $(this).val();
$.ajax({
type: "POST",
data: category_id,
url: "<?= base_url() ?>learning/dependent_dropdown",
success: function(data) {
$.each(data, function(i, data) {
var opt = $('<option />');
opt.val(data.id_type);
opt.text(data.name);
$('#your_second_dropdown_id_name').append(opt);
});
}
});

关于javascript - 从 Combo Cox( View )获取值并发送到 Controller 而不加载页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41444894/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com