How to use Ajax in PHP with JQuery
Ajax is called (Asynchronous JavaScript and XML); it is used to send data into a database or receive data from the database without reloading the whole page.
Example :
1. Promo code in eCommerce website, when user applied promo code in eCommerce website, after successfully applied webpage not reloading just showing coupon applied message to us.
2. When we want to receive complete data of employee or patient on behalf of employee id or patient id without page refreshing
There are several examples in ajax. Just keep one point in your mind: when we want data from a database or send data into a database without page reload.
Solution :
HTML Code :
<select id="empid">
<option id="1">Rakesh kumar</option>
<option id="2">Rajesh kumar</option>
<option id="3">Deepak Mathur</option>
</select>
<div id="searchdiv"></div>
</div>
Jquery Code :
$('#empid').change(function () {
$enqid = $('#empid').val()
$.ajax({url:"php page url",
method:"POST",
data:{empid:$empid},
success:function(data){
if(data){
$('#searchdiv').html(data);
}
else{
alert('No data found');
}
}});
});