我希望两个表中的所有细节都使用单个id,而不使用Ajax刷新页面
这是我的按钮和div:-
<button id="brand" data-b_id="21">brand</button>
<div id="#showdata"></div>## 这是我的javascript:-
$('#brand').click(function() {
show_product();
function show_product() {
var b_id = $('#brand').data('b_id');
//alert(bid);
$.ajax({
type: 'POST',
url: '<?php echo base_url('index.php/Airtel/get_bdid')?>',
dataType: 'JSON',
data: {
b_id: b_id
},
success: function(data) {
var html = '';
var i;
for (i = 0; i < data; i++) {
html += '<tr>' +
'<td>' + data[i].b_name + '</td>' +
'<td>' + data[i].d_name + '</td>' +
'<td>' + data[i].d_id + '</td>';
};
$('#showdata').html(html);
}
});
}
});这是我的控制器:-
public function get_bdid(){
$b_id=$this->input->post('b_id');
$data=$this->mymod->get_bdid($b_id);
echo json_encode($data);
}这是我的模型:-
public function get_bdid($b_id){
$this->db->where('b_id',$b_id);
$this->db->select('*');
$this->db->from('brand');
$this->db->join('dth', 'dth.b_name = brand.b_name');
$query = $this->db->get();
return $query->result();
} 发布于 2020-04-02 01:21:05
也许,在浏览器开发模式中存在许多错误。
success: function(data) {
console.log(data);
}。
success: function(data) {
var obj = JSON.parse(data);
console.log(obj);
// or loop
}https://stackoverflow.com/questions/60975624
复制相似问题