Php Newsfeed With Reload
I'm have a PHP and MYSQL based newsfeed. To get new content, the user has to refresh the page. I'm working on a push system that would update the element with new posts without ref
Solution 1:
Sounds like a job for Ajax!
Also if you want to make the work really easy, use jquery. The Syntax would look something like this:
$.ajax({
type: "post", url: "/SomeController/SomeAction",
success: function (data, text) {
//....
},
error: function (request, status, error) {
alert(request.responseText);
}
});
EDIT
to have the page update when a user clicks on a "show more content" link you can either use javascripts onclick function or use jquery's built in stuff.
Regular JS:
<somekindOfLinkOrButton onclick("moarStories();")/>
<script>functionmoarStories(){
//ajax here
};
</script>
Jquery way (much eaiser)
<script>
$("#ElementId").click(function(){
//ajax here
});
Solution 2:
You just send a request to the server and server tries to keep the connection alive until you get new update. When you get new update from the database, you just push it to the client and close this connection
Post a Comment for "Php Newsfeed With Reload"