CodeIgniter Forums

Full Version: ajax call to On success to redirect to a different page with data from controller
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
hi,
I spend number of days to solve this issue.I want to echo the values in "view_print_increment_form", passed from the controller "print_increment_form". this is my source code. i'm unable to echo values. 
Can any one pls help me to solve this?


   
    function save()
  {
   
    var url;
    url = "<?php echo site_url('index.php/ClerkAE/send_increment_form')?>";

    $.ajax({
        url : url,
        type: "POST",
        data: $('#form_increment').serialize(),
        dataType: "JSON",
        success: function(data)
        {
            console.log(data);
            if(data.status)
            {
               $('#modal_increment').modal('hide');                              
               location.reload();
               window.open("<?php echo site_url('index.php/ClerkAE/print_increment_form')?>/"+data.ID , "popUpWindow","height=400,width=600,left=10,top=10,scrollbars=yes,menubar=no");
            }
            else
            {
                for (var i = 0; i < data.inputerror.length; i++) 
                {
                    $('[name="'+data.inputerror[i]+'"]').parent().parent().addClass('has-error'); 
                    $('[name="'+data.inputerror[i]+'"]').next().text(data.error_string[i]); 
                }
            }            
        },
        error: function (jqXHR, textStatus, errorThrown)
        {
            alert('Error in SAVE data');

        }
    });
  }

////////////////////////////controller/////////////////

 public function send_increment_form()
                  {
                 $data_increment_step = array(   
                 'step' => $this->input->post('salary_step'),
                 'amount' => $this->input->post('amount'),
                 'incre_tbl_id' => $this->input->post('id'),                  
                   ); 
                  
                  $this->load->model('Model_user');
$insert=$this->Model_user->model_send_increment_form(array('id' => $this->input->post('id')),$data_increment_step);
                  $this->session->set_flashdata('message', 'Your data updated Successfully.......');
                  echo json_encode(array("status" => TRUE, "ID" => $insert));         
                  
                        }
                        
            public function print_increment_form($id){            
            $this->load->model('Model_user');
            $data['user_info']=$this->Model_user->model_print_increment_form($id);      
            $this->load->view('ClerkAE/view_print_increment_form',$data);           
            }

/////////////////model///////////////

 public function model_send_increment_form($where, $data)
{       
$this->db->update('increment', array('send_form_bit'=>1), $where); 
                $this->db->insert('increment_step', $data);
                return $this->db->insert_id(); 
}
        
        
         public function model_print_increment_form($id)
         {
       
              $query = $this->db->query("SELECT i_s.*,e.emp_no, e.initials, e.last_name, c.designation, c.grade, d.dept_name,f.faculty_name "
                      . "FROM increment_step i_s, emp_pmt e, cadre c, increment i, dept d, faculty f "
                      . "WHERE i_s.id='.$id.' AND i_s.incre_tbl_id=i.id AND i.emp_no = e.emp_no AND i.cid=c.id AND d.id=e.dept_no AND d.faculty_id=f.id ");
             
               return $query->result(); 
         }

//////////////////////////////////////////////////////////////view_print_increment_form////////////////

<?php


foreach($user_info as $emp){
                
echo "<br>".$emp->emp_no."</br>";

echo "<br>".$emp->initials."".$emp->last_name." </br>";

echo  "<br>".$emp->designation."</br>";

echo  "<br>".$emp->grade."</br>";

echo  "<br>".$emp->dept_name."</br>";

echo  "<br>".$emp->faculty_name."</br>";

echo  "<br>".$emp->step."</br>";

echo  "<br>".$emp->amount."</br>";
}

?>
Which part you have problem echoing out? Also, the first part, is that a JS file or a view file that has the JS function declaration in it?
(10-10-2018, 03:35 AM)Pertti Wrote: [ -> ]Which part you have problem echoing out? Also, the first part, is that a JS file or a view file that has the JS function declaration in it?

problem in last echoing out in view_print_increment_form. it echo nothing. 

first part is view file that has the JS function declaration in it. there is buttion call EDIT and  when onClick it shows a Bootstrap modal called show_increment_form(). when that form submitted with save button, i want to go for  different page called "view_print_increment_form" and echo the values as last echoing part
1) ClerkAE should be lowercase.
2) Model_user should be lowercase.
that is not the case here.
@jackey,

Are there any error messages in the CI log? Have you tried to echo out the output to see if there is any data from the query?
there are no error messages and it echo nothing. 
view_print_increment_form is empty page.

Query give the data as out put. query is correct. problem may be in the way how passing the data from controller to view or model to controller
So if you echo out query result in your model_print_increment_form method, it returns correct data?
when i write the query in phpmyadmin->sql pannel , it works , but it doesn't echo out query result in my  view_print_increment_form.php page.
how to echo query result in model_print_increment_form method?
Adding this should show you last query that was run, any SQL errors and result. Make sure in your database config you have save queries option set to TRUE.
From that you can check the query put together was correct and follow up from there.

PHP Code:
public function model_print_increment_form($id)
{
    
$query $this->db->query("SELECT i_s.*,e.emp_no, e.initials, e.last_name, c.designation, c.grade, d.dept_name,f.faculty_name "
        
"FROM increment_step i_s, emp_pmt e, cadre c, increment i, dept d, faculty f "
        
"WHERE i_s.id='.$id.' AND i_s.incre_tbl_id=i.id AND i.emp_no = e.emp_no AND i.cid=c.id AND d.id=e.dept_no AND d.faculty_id=f.id ");

    
// add this
    
echo '<pre>'print_r($this->db->last_query(), true), '</pre>';
    echo 
'<pre>'print_r($this->db->error(), true), '</pre>';
    echo 
'<pre>'print_r($query->result(), true), '</pre>';
             
    return 
$query->result(); 

Pages: 1 2