Here is my code.
back end code (express)
router.get('/principal/leave/approval/:id',function(req,res){
console.log('requested');
var approval;
if(req.body.approve){
approval=true;
}else{
approval=false;
}
leaveDB.update({_id:req.params.id},{approved:approval},function(err){
if(err){
console.log(err);
}else{
res.send('success');
}
});
});
here is the front end
<input type='button' value="Approve" id="Approve" class="btn<%=details._id%>"/>
<input type='button' value="Disapprove" id="Disapprove" class="btn<%=details._id%>"/>
</form>
<script>
$(document).ready(function(){
$('.btn').on('click',function(){
var id=this.className.slice(4);
$.ajax({
type:'GET',
url:'/principal/leave/approval/'+id,
data:{approval:this.id},
success:function(data){
alert('success');
}
});
});
});
</script>
when I run this I dont even see the "requested" printed in the console. Is there any fault in my code or should I use something else to make a request like this? (I am using ejs as the view engine)