Get a Single Row from the Database Using Ajax in Codeigniter

How to get a row from database using ajax in codeigniter

in model

function get_program_specific($program_id){
$temp=array();
$query=$this->db->query("SELECT * FROM programs WHERE program_id='".$program_id."'");
$temp= $query->row_array();
echo $temp['program_name'];
}

in controller change the line

$data['programs']= $this->program_management_model->get_program_specific($program_id);

with

$this->program_management_model->get_program_specific($program_id);

and finally in javascript

alert(row);

please let me know if you face any problem.

Get a single row from the database using AJAX in CodeIgniter?

Try this:

$(function(){ // start of doc ready.
$(".faq_title").click(function(e){
e.preventDefault(); // stops the jump when an anchor clicked.
var title = $(this).text(); // anchors do have text not values.

$.ajax({
url: 'faq/get_faq_data',
data: {'title': title}, // change this to send js object
type: "post",
success: function(data){
//document.write(data); just do not use document.write
console.log(data);
}
});
});
}); // end of doc ready

The issue as i see is this var title = $(this).val(); as your selector $(".faq_title") is an anchor and anchors have text not values. So i suggested you to use .text() instead of .val().

How to pass a particular row to ajax function in View in Codeigniter

Simply Echo Your Result,

public function create_goal(){

$id=$this->input->post('c_id');

$result_updated_record = $this->course_model->get_last_course_rec($id);

if($result_updated_record!='false')
{
echo json_encode($result_updated_record);
}
else
{
echo json_encode($result_updated_record);
}

}

Codeigniter ajax - retrieving rows in Codeigniter with JQuery not working

I fixed it, but I don't know if it's a good practice:

basically I create another view (everything printed here will be updated in my div via ajax):

controller:

function get_invoices()
{

$data['login2'] = $this->login_select->get_login($company);
$this->load->view('ajaxtest', $data);///the trick

}

JQuery in the view is the same.

the model (nothing weird here):

public function get_login($myid)
{

$query = $this->db->get_where('user', array('id_user'=>$myid));

return $query->result_array();

}

and the trick is create another view in this case ajaxtest.php:

<?php

echo sizeof($login2) . " ";

foreach ($login2 as $login2_item):

echo $login2_item["name"];

endforeach;

?>

If anyone needs this in the future.



Related Topics



Leave a reply



Submit