You can use these things to make such functionalities.
- PHP JSON Based API
- PHP Socket Based JSON API
- Socket IO based API
All these API can easily be parsed by AngularJS or jQuery
For PHP, How to make an API
<?php //Set header for Javascript to recognize it as the JSON output header('Content-Type:application/json;'); //I am using GET parameters, but POST can also be used and can make amazing APIs switch($_GET['action']){ case "addlike": //SQL Query passed to add a like as facebook //Set the output array to provide json Output, here's the example $output['status'] = 200; $output['message'] = 'Like Added'; break; case "addcomment": break; } echo json_encode($output);
To use above code, the URL would be:
http://yourserve/youfile.php/?action=addlike
And the Output would be
{ "status":200, "message":"Like Added" }
How to use it in jQuery
/** For Example you have like button with class="btnlike" **/ $('.btnlike').on('click',function(){ $.get('http://yourserve/youfile.php',{action:'addlike'},function(data){ if(data['status'] == 200){ alert('You Liked the Post'); } }); });
How to use in AngularJS
app.controller('myCtrl',function($scope,$http){ $scope.message = ''; $scope.addlike = function(){ $http.get('http://yourserve/youfile.php',{action:"addlike"}).success(function(data){ if(data['status']==200){ $scope.messages = 'You liked the post'; } }); }; });