带有重新加载的PHP Newsfeed [英] PHP Newsfeed with Reload

查看:70
本文介绍了带有重新加载的PHP Newsfeed的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个基于PHP和MYSQL的新闻源.要获取新内容,用户必须刷新页面.我正在开发一个推送系统,该系统将使用新帖子更新元素,而无需刷新整个页面.我该怎么办?

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 refreshing the whole page. How would I go about that?

推荐答案

听起来像 Ajax的工作!

如果您想简化工作,请使用 jquery .语法看起来像这样:

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);
}
});

编辑

要在用户单击显示更多内容"链接时更新页面,您可以使用javascripts onclick函数或使用jquery的内置内容.

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.

常规JS:

<somekindOfLinkOrButton onclick("moarStories();")/>

<script>
    function moarStories(){
        //ajax here
    };
</script>

jQuery方式(更加轻松)

Jquery way (much eaiser)

<script>
   $("#ElementId").click(function(){
         //ajax here
   });

这篇关于带有重新加载的PHP Newsfeed的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆