Getting data through Ajax is very cool, and when we can reuse the CodeIgniter views to get the Ajax data, the overall user experience become much more enhanced. So, in this tutorial I would show you how to call jquery Ajax in controller.
This is a tutorial here I am not going to tell about how to get the Ajax data but just how to call Ajax in controller.
Jquery Ajax call to Controller
$('.report').blur(function(){
var reportno = $(this).val();
$.ajax({
type:'POST',
url:"Challan/CheckReportNumber",
data: {reportno: reportno},
dataType: 'JSON',
success:function(data){
alert(data);
}
});
});
Codeigniter Controller Function
public function CheckReportNumber()
{
$reportno = $this->input->post('reportno');
print_r($reportno);
exit;
}
This will alert result of your controller.
here you can encode your data in json and xml to. we will see in next tutorial how to encode and decode data in to json format.