gpt4 book ai didi

javascript - Codeigniter 中的 Ajax 仅更改 View 中的 div

转载 作者:行者123 更新时间:2023-11-28 00:20:48 26 4
gpt4 key购买 nike

Hello, I want to be able to change only part of the div in my view i have tried to write the codes but they are not working perfectly. how it works is when i click the button it suppose to sent the value to a js then using js to sent data to the controller.

脚本:

  function getValue(datas){
alert(datas) ;
var mydiv = datas;
$.Ajax({
type:"post",
url:<?php echo base_url('/mama/load_view/');?>
data:{"mydiv":mydiv},

success:function(data){
$('#mang_server').html(data);
}
});
}

PHP:

  foreach($student_prof as $row){
$gen = "GeneralInformation";
echo '<input type="submit" value="GeneralInformation" class="btn btn-primary active" name="general" id="submit" onclick="getValue("'.$gen.'")">';
echo '</div>';

}

The Controller code

public function load_view(){

$data1 = $this->input->post('mydiv');

if($data1 == "GeneralInformation"){

$this->load->view('student/profile_view');
}
else {
$this->load->view('student/profile_view');
}


}

最佳答案

使用jquery加载函数。

 function getValue(datas){


var mydiv = datas;
url = "<?php echo base_url('/mama/load_view');?>/" + mydiv;
$('#mang_server').load(url);

}

Controller

public function load_view($data1){



if($data1 == "GeneralInformation"){

$this->load->view('student/profile_view');
}
else {
$this->load->view('student/profile_view');
}


}

关于javascript - Codeigniter 中的 Ajax 仅更改 View 中的 div,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30049133/

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