[英]bootstrap modal dynamic data from database
I want open model and get model content dynamic but when i call ajax file and get response data then model not open and i cant access json response data in php code . 我想要打开模型并获得动态的模型内容,但是当我调用ajax文件并获取响应数据时,模型不能打开,我无法访问php代码中的json响应数据。 When I put my model in ajx file and get html response then response success but model can't open.please help me to fix issue.
当我将我的模型放在ajx文件中并得到html响应然后响应成功但模型无法打开。请帮助我解决问题。
<script>
function test(id) {
$.ajax({
type: "GET",
url: "<?php echo base_url(); ?>index.php/Appointment/get_model",
data: "id=" + id,
cache: false,
success: function(data) {
$("#model_test").html(data);
$("#myModal2").modal('show');
//displayRecords();
}
});
}
</script>
This one is my ajax file get_model.php
: 这个是我的ajax文件
get_model.php
:
<?php
if (isset($_GET['id'])) {
$id = $_GET['id'];
$query = $this->db->query("select * from appointment where id='" . $id . "'");
$result = $query->row();
print_r($result);
die;
//echo(json_encode($result));
}
?>
<div id="myModal2" class="modal fade" role="dialog">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-body">
<div class="col-lg-12">
<div class="form-group col-lg-3 col-md-3">
<label for="usr">Doctor Name:</label>
</div>
<div class="form-group col-lg-7 col-md-7 ">
<input type="name" class="form-control input-lg" name="email" id="email_id" value="<?php
$result->name;
?>" placeholder="Doctor Name" required>
</div>
<div class="form-group col-lg-3 col-md-3">
<label for="usr">Contact No:</label>
</div>
<div class="form-group col-lg-7 col-md-7 ">
<input type="name" value="<?php
$result->contact_no;
?>" class="form-control input-lg" name="email" id="email_id" placeholder="Patient Name" required>
</div>
</div>
</div>
And this one is my html code i want to open model here with dynamic content: 这个是我的HTML代码我想在这里用动态内容打开模型:
<div id="model_test">
</div>
<?php
foreach($result as $row)
{
<td onclick="test(<?php echo $row->id;?>)" data-toggle="modal" data-id="<?php echo $row->id;?>" data-target="#myModal2" ><?php echo ucfirst($row->name);?></td>
}
you have a problem in the div closing tags, kindly check that all div tags are closed properly, try the below code 你在div结束标签中有问题,请检查所有div标签是否正确关闭,请尝试以下代码
<div id="myModal2" class="modal fade" role="dialog">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-body">
<div class="col-lg-12">
<div class="form-group col-lg-3 col-md-3">
<label for="usr">Doctor Name:</label>
</div>
<div class="form-group col-lg-7 col-md-7 ">
<input type="name" class="form-control input-lg" name="email" id="email_id" value="<?php $result->name; ?>"
placeholder="Doctor Name" required >
</div>
<div class="form-group col-lg-3 col-md-3">
<label for="usr">Contact No:</label>
</div>
<div class="form-group col-lg-7 col-md-7 ">
<input type="name" value="<?php $result->contact_no; ?>" class="form-control input-lg" name="email" id="email_id"
placeholder="Patient Name" required >
</div>
</div>
</div>
and this one is my html code i want to open model here with dynamic content
<div id="model_test">
</div>
</div>
<td onclick="test(<?php echo $row->id;?>)" data-toggle="modal" data-id="<?php echo $row->id;?>" data-target="#myModal2" ><?php echo ucfirst($row->name);?></td>
You did not use MVC programming pattern! 你没有使用MVC编程模式! You use database code into a view?!
您将数据库代码用于视图吗?! Please make a Controller with the function:
请使用以下功能制作控制器:
function get_model(){
$this->load->model('get_model');
$value = $this->get_model->your_db_data_retrieve_model_function(data);
$data = json_encode($value);
$this->output
->set_content_type('application/json')
->set_output($data);
}
also a model (retrieve data from database) is needed: 还需要一个模型(从数据库中检索数据):
function retrieve_data($id) {
. ....
return $data;
}
remember to use a controller to get the data from $_GET using 记得使用控制器从$ _GET中获取数据
$this->input->get('your_variable_name')
passing it to model (the ID). 将它传递给模型(ID)。
Consider to read the principle of MVC (model-view-controller) pattern. 考虑阅读MVC(模型 - 视图 - 控制器)模式的原理。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.