我遇到了一个问题,我要伤害mvc模式,所以我宁愿问你该怎么做。我用jQuery .post()-method得到了一个每10秒刷新一次的页面。
setInterval(function() {
$.post("http://XYZ.de<?php echo $this->webroot."Posts/index"; ?>", { liveUpdate: "true" },
function(response) {
$('#loadingContent').html(response);
}
);
}, 10000);
现在,在"Posts/index"放置的地方,我必须调用蛋糕的PostsController.php,它允许我重置变量。
但它不工作的方式和响应是充满了所有的html的正常页面调用,但我只想有纯php变量更新没有html附加到该div。
我做错了什么?提前感谢您的耐心。
因为你的数组是复杂的多层,你不想解析JSON,我看到的唯一方法就是使用jQuery load()。
setInterval(function() {
jQuery("#RefreshMeOnPage")
.load("http://XYZ.de<?php echo $this->webroot."Posts/index"; ?> #RefreshMeInResults > *", {liveUpdate: "true"});
}, 10000);
向服务器发出post请求,将id为RefreshMeOnPage
的已有元素的内容替换为新接收到id为RefreshMeInResults
的元素的内容。文档http://api.jquery.com/load/。
注意:刷新率仍然是10秒,我认为你应该看看ajax comet解决方案http://cometdaily.com/maturity.html。它只在有变化时接收数据,尽管它需要一些配置。