Issue
I want to call a function of cakephp controller using jquery ajax from my layout file default.ctp and want to set return response in notification section of every page but its not working.
This is my controller method:
public function cartItemCount(){
$conn = ConnectionManager::get('default');
$result = $conn->query("SELECT count(*) as total_count FROM carts")->fetchAll('assoc');
$this->response->body($result[0]['total_count']);
return $this->response;
}
This is my jquery code:
<script type="text/javascript">
$(document).ready(function(){
$.get('<?php echo SITEURL;?>/NewOrders/cartItemCount',function(res){
console.log(res);
$(".cart_item").text(res);
});
});
</script>
When I write this script in each and every view its working correct but I want write this script in default view so its work for all view without writing code in every view file. Please someone help me out.
Solution
You can store total count in session and then retrieve that session where you want to call.
Answered By - Kishor
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.