I fetch data from controller and it shows in console.log(data)
and I want to show that data in table
View:
<?php include 'header.php';?>
<script src="/assets/js/plugins/jquery.min.js"></script>
<script src="/assets/js/jquery.validate.min.js"></script>
<script>
var jq = $.noConflict();
</script>
<table id="enquiry_table">
<thead>
<tr>
<th>From</th>
<th>TO</th>
<th>Date</th>
<th>Status</th>
</tr>
</thead>
<tbody>
<?php
foreach ($records as $rec){
?>
<tr>
<td><?php echo $rec[0]->lr_from; ?></td>
<td><?php echo $rec[0]->lr_to; ?></td>
<td><?php echo date('d-m-Y',strtotime($rec->date));?></td>
<td><?php echo $rec->status;?> </td>
</tr>
<?php
}
?>
</tbody>
</table>
<script type="text/javascript">
function status_form(){
var lr_no = jq('#lr_no').val();
jq.ajax({
url :"https://demo.barque.online/sitecontroller/StatusController/fetchStatus",
type:"POST",
dataType: "json",
data:{
lr_no:lr_no,
},
success: function(data)
{
console.log(data);
},
error:function(data)
{
alert("error message"+data);
},async:false,
});
}
</script>
<?php include 'footer.php'; ?>
Controller:
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class StatusController extends CI_Controller {
public function __construct()
{
header('Access-Control-Allow-Origin: my url');
header('Access-Control-Allow-Credentials: true');
header('Access-Control-Max-Age: 604800');
header("Access-Control-Allow-Headers: Origin, Content-Type, Accept, Access-Control-Request-Method");
header("Access-Control-Allow-Methods: GET, POST");
parent::__construct();
$this->load->model("sitemodel/StatusModel",'sModel');
}
function fetchStatus(){
$lr_no = $this->input->post('lr_no');
$statusResult['records'] = $this->sModel->fetchRecords($lr_no);
echo json_encode($statusResult);
}
}