I am creating the event but not able to detect the event using Ajax. I am working on Codeigniter and I have the following code:-
View.php
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
<script>
$("#promocode").on("input",function(){
console.log('handler detected');
var valueModel = $(this).val();
$.ajax({
url : "bookings/getVCode",
type: "post",
data: {"valueModel":valueModel},
success : function(data){
// console.log(data);
$("#msg").html(data);
},
});
});
</script>
<label for="promocode">Promo Code</label><div id="msg"></div>
<input class="form-control" type="text" id="promocode" name="promocode" >
My Controller:
Bookings.php
function getVCode()
{
$data = $this->NewQuoteModel->checkVoucherexist();
$option ="";
if(count($data) > 0){
$option .="<p> Your Voucher is Valid! </p>";
} else {
$option .= "<p> Your Voucher is not Valid! </p>";
}
echo $option;
}
And My Modal
NewQuoteModel.php
function checkVoucherexist()
{
$model = $this->input->post('valueModel');
$this->db->select('*');
$this->db->from('Vouchers');
$this->db->where('Name', $model);
$query = $this->db->get();
if ($query->num_rows() > 0) {
return $query->result();
} else {
//echo 'No Make found';
}
}