javascript - Server-side function throws a php error when accessed through ajax -


i using codeigniter-bonfire web application lets site administrator verify or unverify user's "stuff" (like name , work experience). admin can choose dropdown list "verify" or "unverify". when value of dropdown list changes, ajax call made server. server echoes out value javascript, inserts view page.

everything working--the database changed accordingly, echoed value correct--but javascript catches error message server-side.

the error is: trying property of non-object.

i've done echo's before , after errors supposedly occur, object prints out fine. i'm @ loss because didn't used happen.

the annoying thing error seems happen randomly. can when verification goes verified unverified , vice versa. error prints out before echoed value , disappears of own accord (but not before being displayed split second.

thank in advance.

the javascript looks this:

$(document).on('change', '.verified', function(event) {     var id = $(this).attr('id'); $.ajax({     type: "post",     url: 'http://theurl.com/module/controller/verify/100/files/24' }).done(function(msg) {     $('#timestamp_'+id).text(msg); }); 

function verify looks this:

public function verify($user_id, $other_table, $other_id) {     $this->load->model('profile/verifiable_items_model', 'vi_model');     $item = $this->vi_model->find_by(array(                 'user_id' => $user_id,                 'other_table' => $other_table,                 'other_id'  => $other_id             ));      $update_date = 0;      if ($item->verified == 0) // error here     {         $update_date = date('y-m-d h:i:s', time());         $data = array('verified' => 1, 'notes_time' => date('y-m-d h:i:s', time()), 'verified_by' => $this->current_user->username);     }     else     {         $data = array('verified' => !($item->verified), 'notes_time' => null); // error here     }      $this->vi_model->update($item->id, $data);      echo $update_date; } 

since object on line of error $item object, means item not set or @ least not object (maybe null or false). since find_by method return first object matches, guess filter doesn't match @ all.

you have done echoes before , after. positively sure of that? try var_dump'ing or print_r'ing $item , see comes with. if not receiving expected object, verify parameters passing on the find_by function see if correct. (maybe reason user_id not passed correctly, assume might passed cookie or session expired or that)


Comments

Popular posts from this blog

node.js - Bad Request - node js ajax post -

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -