Welcome Guest, Not a member yet? Register   Sign In
Ajax data from controller
#5

Thanks again and here is my corrected code.

Controller:
public function booking_user() {
$id = $this->input->post('user_list');
$query = $this->Booking_model->get_book_user($id);
echo json_encode($query);
}
This gets the posted ID from the ajax script and sends that to the model and then is returned back to the view as json.

View:
<script>
$(document).ready(function(){
$('#user_list').change(function(){
var id = $('#user_list').val();
console.log(id);
$.ajax({
type: 'POST',
url: '<?php echo base_url();?>' + 'home/booking_user',
dataType: 'json',
data: {user_list: id},
success: function(data){
console.log(data);
$('#firstname').val(data[0].FirstName);
$('#lastname').val(data[0].LastName);
$('#email').val(data[0].Email);
$('#phone').val(data[0].Phone);
$('#playerone').val(data[0].FirstName + ' ' + data[0].LastName);
}
});
});
});
</script>
Reply


Messages In This Thread
Ajax data from controller - by scott3322 - 03-27-2018, 10:21 AM
RE: Ajax data from controller - by jreklund - 03-27-2018, 11:50 AM
RE: Ajax data from controller - by scott3322 - 03-28-2018, 08:17 AM
RE: Ajax data from controller - by jreklund - 03-28-2018, 11:31 AM
RE: Ajax data from controller - by scott3322 - 03-28-2018, 12:07 PM
RE: Ajax data from controller - by InsiteFX - 03-28-2018, 08:20 PM
RE: Ajax data from controller - by jordi_1h - 04-28-2020, 07:37 PM



Theme © iAndrew 2016 - Forum software by © MyBB