Javascript database lookups

The place to go for any sort of help with using or developing with Bonfire.
Post Reply
Posts: 1
Joined: 09 Dec 2017, 23:59

10 Dec 2017, 00:17

G'day everyone.

I discovered Bonfire (0.8.3) a week or so ago while looking for an easy framework to create some simple web apps for my workplace. So far, it seems like just what I need - the module builder is amazing!

I have very little knowledge and experience with web technologies (consider me a noob), so I'm hoping someone here can lend me a hand.

I have a "create" view with a field for Employee ID. As soon as numbers are entered into the field, I'd like to perform a database query for the employee's name and display it on the page before I fill out the other fields and submit. I know that Bonfire has Javascript libraries built-in, but I have no idea how to use them to achieve my goal.

Can someone please point me in the right direction for some AJAX goodness?

Posts: 1
Joined: 08 Aug 2018, 13:15

08 Aug 2018, 13:48

Hey Buddy,
This will be js code:
function get_record()
var ci_csrf_token = "<?php echo $this->security->get_csrf_hash() ?>";
var courtid=$("#courtid option:selected").val();
if ($('input[name="usertype"]:checked').val() == 'external') {

var dateText=$("#startdate").val();
type: "post",
url: "index.php/admin/mainmasters/pdsa_ground_booking_form/getsoldtimeslots",
cache: false,
data: {courtid:courtid, ci_csrf_token: ci_csrf_token},

success: function (data) {

var myObj = jQuery.parseJSON(data); console.log(myObj); //alert(myObj);
var soldtimeslotsbycourt = $.map(myObj.timeslots, function(value, index) {
return [value];
var instituteslots = $.map(myObj.instituteslots, function(value, index) {
return [value];
//console.log( soldtimeslotsbycourt);
error: function () {
alert('Error while request..');
controller function:

public function getsoldtimeslots(){
$res=$this->pdsa_ground_booking_form_model->soldtimeslots('',$courtid); //echo $this->db->last_query();exit;
echo json_encode($res); exit;

Model Function:

public function soldtimeslots($bookingid='',$courtid='')
$this->db->join('institute_master', 'pdsa_ground_booking_form.instituteid = institute_master.institute_id','left');

$this->db->where('id !=',$bookingid);
if(in_array($courtid, array(3,4))){
$this->db->where('courtid ='.$courtid.' or courtid =2');
}else if(in_array($courtid, array(2))){
$this->db->where_in('courtid', array('2','3','4'));
$this->db->where('courtid =',$courtid);
$query = $this->db->get();


foreach($result as $row){


foreach($timeslots2 as $timeslot){


return $array;


Post Reply