3

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.

enter image description here

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
}
4
  • Please post the ajax code. Commented Dec 24, 2013 at 15:47
  • I think this is a great way to learn something, kudos to you on that one! I agree though, please post the AJAX code. I'm assuming you don't have a "failure" clause in your AJAX code. Are you using a library of any sort? If you're using raw AJAX, just do a conditional on response code 500 Commented Dec 24, 2013 at 15:53
  • 2
    I'm also searching for a solution for this problem. Thanks @Sami Commented Dec 24, 2013 at 16:00
  • Added the ajax code and got the perfect answer as well.. Commented Dec 24, 2013 at 16:17

1 Answer 1

5

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.

Sign up to request clarification or add additional context in comments.

4 Comments

Great. Thanks a lot...I had nothing like $db['default']['db_debug'] in my config/databas.php, but i added the line $db['default']['db_debug'] = FALSE; When i saw the answer i was surprised what is this that how it can work, but its working perfectly :). Thanks again
You're welcome. I think by default it is TRUE so you need to do as you did and explicitly set it to FALSE.
I have got my problem fixed but question is still open. Could you please add little more (or i should open another question) that why i get this error al-right when doing work without ajax and even with ajax i get it in console but not in controller and as ajax respose-text in my view. I Also get 500 internal error, u can see the image
You can look through system/database/DB_driver.php and related files to see where the issue is. If you notice, the error returned in _error_message and the error that gets displayed as in your screenshot are very different. The _error_message will just contain the error string whereas the displayed version will have styling, etc. It appears that if debug is on, it displays the error and exits, not getting to the point where it would populate _error_message. I'm not sure why -- it might be a bug. 500 is the status set by CI - appropriate because it's an internal server error.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.