处理数据库错误使用Ajax请求,codeigniter [英] handling database error with ajax request codeigniter
问题描述
我故意制造错误,即使用coulmn的名字写错了,学习如何与codeigniter AJAX调用处理错误之一。
最后的评论在年底控制器的功能是我的问题/问题
我AJX code 跟随。我使用的 当作ajaxForm插件 。它让我从控制器完全所有反应,但问题是只有
我无法从模型控制器的响应,而使用Ajax调用是一点都不奇怪
$('#myForm会)。当作ajaxForm
({
成功:函数(responseText的)
{
如果(的responseText!=1)
$('#反馈)HTML(responseText的);
}
});
以下是确切的错误的快照,我可以在控制台中,但无法看到得到控制,因此考虑。它描述了完整的错误,即未知列在给定的查询,但我只捕获上半部分。
我的模式功能小于
公共职能的updateItem($ ID,$数据,$ TBL)
{
$这个 - > DB-化合物其中('身份证',$ id)的;
$ R = $这个 - > DB->更新($ TBL,$数据);
如果($ R)
返回$ R;
其他
{
$ R = $这个 - > DB-> _error_message();
返回$ R;
}
}
我的控制器功能 code
公共职能upadteme()
{
$ R = $这个 - > ajax_model->的updateItem($ UID,$数据,用户);
回声$ R - 。 //无法获取该回波工作
//使用AjaxCall的(通过AJAX调用控制器)时,否则罚款
}
它看起来像类将不会填充 _error_message
如果 db_debug
是它似乎是在默认情况下在其上。
在的config / database.php中
,设置
$分贝['默认'] ['db_debug'] = FALSE;
,然后再试一次。
I am intentionally making error i.e. using one of the coulmn's name wrong to learn how to handle the error with ajax call with codeigniter.
Last Comment in controller function at the end is my question/problem
My AJX Code is following. I am using ajaxform plugin. It shows me all response from controller perfectly but problem is only
I am unable to get response from model in controller while using ajax call that is little weird
$('#myForm').ajaxForm
({
success: function(responseText)
{
if(responseText != "1")
$('#feedback').html(responseText);
}
});
Following is snapshot of exact error which i can see in console but unable to get in controller and hence in view. It describes complete error i.e unknown column in given query, but i captured only upper portion.
My model function is below
public function updateItem($id, $data, $tbl)
{
$this->db->where('id', $id);
$r = $this->db->update($tbl, $data);
if($r)
return $r;
else
{
$r = $this->db->_error_message();
return $r;
}
}
My controller function code
public function upadteme()
{
$r = $this->ajax_model->updateItem($uid, $data, 'users');
echo $r." -- "; // Unable to get this echo working
//when using ajaxcall (calling controller through ajax) otherwise fine
}
It looks like the class will not populate _error_message
if db_debug
is on which it appears to be by default.
In config/database.php
, set
$db['default']['db_debug'] = FALSE;
and try again.
这篇关于处理数据库错误使用Ajax请求,codeigniter的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!