This is the very first time i am using AJAX. I totally don't understand the flow of data here. please help.and i am doing it in codeigniter This is my code EDITED:
The js function in my view page:
function selectHandler() {
var selectedItem = chart.getSelection()[0];
if (selectedItem) {
var topping = data.getValue(selectedItem.row, 0);
$.post("http://localhost/offlearn/index.php/ctrl_offapp/trail2",
{
top: topping,
},
function(res,status){
// alert(res);
document.getElementById('tablePrint').innerHTML = res;
});
}
}
trial2
is my controller function.
Can you help?
**The trial2 function in codeigniter is ** :
public function trail2(){
$var=$this->input->post('top');
$data['ts'] = $this->offapp_database->get_tasks();
$data['u'] = $this->offapp_database->usermaster();
print_r($data['ts']);
exit;
$myTable= '<table><tr><td >TASK NAME</td><td >ASSIGNED TO</td><td >CREATED BY</td></tr>';
foreach($ts->result() as $tk)
{
if ($tk->status == 0 ) {
$myTable.= '<tr><td >'.$tk->taskname.'</td><td >'; foreach($u->result() as $usr)
{ if ($usr->id == $tk->assignto) {echo $usr->fname;}}
$myTable.= '</td><td >';
foreach($u->result() as $usr)
{ if ($usr->id == $tk->createdby ) {echo $usr->fname;}}
$myTable.=' </td></tr>';
$myTable.='</table>';
echo $myTable ;
}
}
}
The functions inthe model:
public function get_tasks()
{
$this->db->select('*');
$this->db->from('tasks ');
$rslt = $this->db->get();
return $rslt;
}
public function usermaster()
{
$this->db->select('*');
$this->db->from('usersmaster ');
$rslt = $this->db->get();
return $rslt;
}
here i tried to display the the table assigned to the variable $myTable in the div 'tableprint' of the view page. and this is the output i get:
CI_DB_mysqli_result Object ( [conn_id] => mysqli Object ( [affected_rows] => 108 [client_info] => mysqlnd 5.0.11-dev - 20120503 - $Id: 76b08b24596e12d4553bd41fc93cccd5bac2fe7a $ [client_version] => 50011 [connect_errno] => 0 [connect_error] => [errno] => 0 [error] => [error_list] => Array ( ) [field_count] => 19 [host_info] => localhost via TCP/IP [info] => [insert_id] => 0 [server_info] => 5.5.5-10.1.16-MariaDB [server_version] => 50505 [stat] => Uptime: 639 Threads: 1 Questions: 11 Slow queries: 0 Opens: 20 Flush tables: 1 Open tables: 13 Queries per second avg: 0.017 [sqlstate] => 00000 [protocol_version] => 10 [thread_id] => 3 [warning_count] => 0 ) [result_id] => mysqli_result Object ( [current_field] => 0 [field_count] => 14 [lengths] => [num_rows] => 77 [type] => 0 ) [result_array] => Array ( ) [result_object] => Array ( ) [custom_result_object] => Array ( ) [current_row] => 0 [num_rows] => [row_data] => )
Please help me to know where i went wrong