Codeigniter ajax不显示html数据
//查看ajax,而不是从控制器返回数据。视图返回[object],[object] ajax不会从控制器返回数据。视图返回[object],[object]ajax不从控制器返回数据。视图返回[object],[object]ajax不从控制器返回数据。视图返回[object],[object]ajax不从控制器返回数据。视图返回[object],[object]ajax不从控制器返回数据。视图返回[object],[object]Codeigniter ajax不显示html数据,codeigniter,codeigniter-2,Codeigniter,Codeigniter 2,//查看ajax,而不是从控制器返回数据。视图返回[object],[object] ajax不会从控制器返回数据。视图返回[object],[object]ajax不从控制器返回数据。视图返回[object],[object]ajax不从控制器返回数据。视图返回[object],[object]ajax不从控制器返回数据。视图返回[object],[object]ajax不从控制器返回数据。视图返回[object],[object] 您的模型函数总是返回FALSE,因为您无法获取数据,并且在每
您的模型函数总是返回FALSE,因为您无法获取数据,并且在每个循环中使用两次,一次在模型中,另一次在控制器中,这在代码中是错误的。是的 模型 控制器
您的型号代码在哪里??并检查控制台显示的错误??函数getvariance{$this->db->select'name,IFNULL quantity,0 AS quantity';$q=$this->db->from'products';if$q->num_rows>0{foreach$q->result AS$row{$data[]=$row;}返回$data;}返回FALSE;}请将此代码放在您的问题模型中。如果模型已经存在,您将无法获得数据库结果$q=$this->db->from'products'->get;您是否已将模型文件加载到构造函数$this->page_construct'products/update_price',$meta,$output中;像这样吗?是的,在ajax中将数据转换成html表单时会出现问题
<script type="text/javascript">
$(document).ready(function() {
$.ajax({
url: "<?= site_url('products/getallvariance') ?>",
type:"GET",
dataType:"html",
success:function(data){
alert('fahad');
// alert(data);
$('#prTable2').html(data);
}
,error: function(data)
{
alert (data);
}
});
});
</script>
//controller get value from the model but not showing data into view through ajax. ajax not return data from the controller. View returns [object], [object]ajax not return data from the controller. View returns [object], [object]ajax not return data from the controller. View returns [object], [object]ajax not return data from the controller. View returns [object], [object]ajax not return data from the controller. View returns [object], [object]ajax not return data from the controller. View returns [object], [object]
function getallvariance()
{
$variance['allvariance'] = $this->products_model->getvariance();
$output = '<tbody>';
foreach ($variance['allvariance'] as $row)
{
$output .= '<tr><td colspan="10" class=" sorting_1">'.$row->name.'</td></tr>';
}
$output .= '</tbody>';
echo $output;
}
//model is the query is correct? ajax not return data from the controller. View returns [object], [object] ajax not return data from the controller. View returns [object], [object]ajax not return data from the controller. View returns [object], [object]ajax not return data from the controller. View returns [object], [object]
function getvariance()
{
$this->db->select('name, IFNULL( quantity, 0 ) AS quantity');
$q = $this->db->from('products');
if ($q->num_rows() > 0) {
foreach (($q->result()) as $row) {
$data[] = $row;
}
return $data;
}
return FALSE;
}
<?php
function getvariance() {
$this->db->select('name, IFNULL( quantity, 0 ) AS quantity');
$this->db->from('products');
$q= $this->db->get();
if ($q->num_rows() > 0) {
return $q->result();
} else {
return FALSE;
}
}
function getallvariance() {
$this->load->model('products_model');// load your model
$variance = $this->products_model->getvariance();
if($variance){
$output = '<tbody>';
foreach ($variance as $row) {
$output .= '<tr><td colspan="10" class=" sorting_1">' . $row->name . '</td></tr>';
}
$output .= '</tbody>';
}else{
$output="error";
}
echo $output;
}