简体   繁体   English

jQuery .post()刷新页面PHP变量,而在Cake PHP中没有泛白

[英]jQuery .post() to refresh the pages PHP-variables without whiteout in Cake PHP

I got a problem and I´m about to hurt the MVC-paradigm, so I rather ask you what to do. 我遇到了一个问题,我即将伤害MVC范例,所以我想问你该怎么做。 I got a page which is refreshed every 10 seconds with jQuery .post()-method. 我得到一个页面,该页面每10秒钟使用jQuery .post()方法刷新一次。

setInterval(function() {
    $.post("http://XYZ.de<?php echo $this->webroot."Posts/index"; ?>", { liveUpdate: "true" },
        function(response) {
            $('#loadingContent').html(response);
        }
    );
}, 10000);

now, where the "Posts/index" is placed I have to call the PostsController.php of Cake which allows me to reset the variables. 现在,在放置“帖子/索引”的地方,我必须调用Cake的PostsController.php,这使我可以重置变量。

But it doesn´t work that way and the response is filled with all the html of a normal page-call but I only want to have the pure PHP-variables updated without html appended to that div. 但是,这种方式行不通,并且响应中充满了正常页面调用的所有html,但我只想更新纯PHP变量,而没有将html附加到该div。

What am I doing wrong? 我究竟做错了什么? Thanks in advance for your patience. 预先感谢您的耐心配合。

Since your array is complex multilevel and you do not want to parse JSON, the only way I see doing it would be using jQuery load(). 由于数组是复杂的多层结构,并且您不想解析JSON,因此我看到的唯一方法是使用jQuery load()。

setInterval(function() {
  jQuery("#RefreshMeOnPage")
    .load("http://XYZ.de<?php echo $this->webroot."Posts/index"; ?> #RefreshMeInResults > *", {liveUpdate: "true"});
  }, 10000);

It will make post request to server and replace contents of existing element with id RefreshMeOnPage with the contents of newly received element with id RefreshMeInResults . 这将使POST请求到服务器,并用编号来取代现有元素的含量RefreshMeOnPage与新接收到的元素的ID为内容RefreshMeInResults Docs http://api.jquery.com/load/ . 文件http://api.jquery.com/load/

NOTE: Still with refresh rate of 10 seconds, I think you should look into ajax comet solution http://cometdaily.com/maturity.html . 注意:仍然以10秒的刷新率,我认为您应该研究ajax彗星解决方案http://cometdaily.com/maturity.html It will receive data only when there is change, although it requires some configuration. 尽管需要进行一些配置,但仅在发生更改时它将接收数据。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM