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
PHP Dynamic Db Page Rewrite Url
Defining a Namespace for Laravel 8 Routes
PHP - Make Multi-Dimensional Associative Array from a Delimited String
Php:Difference Between '&&' and 'And'
Namevaluepair Error "Namevaluepair Cannot Be Resolved to a Type"
How to Run from PHP a Bash Script Under Root User
Set the Option Available for Select Based on Another Select PHP
Extension PHP5 Does Not Parse in Xampp
When Should I Use Closecursor() for Pdo Statements
What's the Best and Easiest Way to Populate a Dropdown Based on Another Dropdown
Dump Facility in C++ Like Var_Dump() in PHP
PHP Code Can Insert Image to Excel File and Open It Correctly in Ms Excel
How to Merge 3 Images into 1 Image via PHP
Laravel 5 Isdirty() Always Returns False
Wordpress, Nginx Proxy and Subdirectory: Wp-Login.PHP Redirects to Domain