当我尝试在函数成功时提醒数据时,我尝试用ajax函数从控制器显示html页面中的数据,但它显示json数据和当前页面的html标记。我无法在表视图中显示数据。请帮帮我。下面显示了代码:
$(".statuss").on("click",'', function(){
var ele=$(this).closest('tr');
var id=document.querySelector('.statuss:checked').value;
var site=document.getElementById('sites').value;
//alert(id);
// alert(site);
var isGood = confirm('Are you Sure??');
if (isGood) {
$.ajax({
type: 'post',
url: "<?php echo site_url("dashboard/get_keyword");?>",
data: {
id:id,
site:site,
},
// dataType: 'json',
success: function(data) {
//console.log(data);
$("#table_result").removeClass("hidden");
$("#table_result_list").removeClass("hidden");
$("#table_result_footer").removeClass("hidden");
$("#table_inputs_head").removeClass("hidden");
alert(data);
//for {
var d = $.parseJSON(data);
//}
alert(d);
var output;
$.each(d,function(i,e) {
// here you structured the code depend on the table of yours
output += '<tr><td>'+e.keyword+'</td><td>'+e.id+'</td></tr>';
// alert(e.keyword);
});
// alert(datas);
$("#table_result_list").html(data);
// $("#table_result_list").append(output);
// alert(data);
}
});
}
}); 发布于 2017-03-23 19:43:06
更改控制器中的标题,如下所示。
header('Content-Type: application/x-json; charset=utf-8');
$result= // your code.......
echo json_encode($result);发布于 2017-03-23 20:44:01
在控制器中打印表,或者创建一个视图文件来打印表,
在ajax函数中
success: function(data) {
$("#table_result_list").html(data);
}https://stackoverflow.com/questions/42974239
复制相似问题