Codeigniter和AJAX从数据库错误中检索/获取数据 [英] Codeigniter and AJAX retrieving/getting data from database error
本文介绍了Codeigniter和AJAX从数据库错误中检索/获取数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我总是进入ajax的错误函数,这是什么问题?
I always land into the error function in ajax, what is the problem here?
我想检索存储在数据库中的img URL,并使用jquery附加它以显示我的img画廊.但是,在执行任何操作之前,我必须确保它始终位于成功函数上,但我始终位于错误函数上……所以我无法继续进行,因此我被困在这里,
I want to retrieve a img url stored in the database and append it using jquery to show my img gallery. But before I can do any of this, I have to make sure it always land on the success function, but I always land on error function... so I can not proceed and I am stuck here,
更新:
检查控制台,它在 success:function(result)
我的脚本:
function load_contents(track_page)
{
$('#loading').show();
$.ajax({
url:'<?php echo base_url('gallery/load_design');?>',
type:'GET',
dataType:'json',
success:function(result)
{
alert("success");
},
error:function()
{
alert("failed"); //it always show the alert failed.
}
});
}
我的控制器:
function load_design()
{
$this->load->model('design');
$this->load-model('profile');
$user_id = $this->profile->retrieve_userid();
$json = $this->design->load_gallery($user_id->id);
echo json_encode($json);
}
我的模特:
function load_gallery($user_id)
{
$query = $this->db->query("SELECT * from designs WHERE user_id = '".$user_id."' LIMIT 9");
return $query->result_array();
}
推荐答案
您应该在页脚中创建第一个全局变量
You should create first global variable in footer
var base_url = "<?= base_url(); ?>";
现在您需要像这样使用
function load_contents(track_page)
{
$('#loading').show();
var ref = new Date();
var url = base_url + "gallery/load_design?=" + ref.getTime();
$.ajax({
url:url,
type:'GET',
cache: false,
success:function(result)
{
alert("success");
},
error:function()
{
alert("failed"); //it always show the alert failed.
}
});
}
这篇关于Codeigniter和AJAX从数据库错误中检索/获取数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文