首页 > 解决方案 > phph 在使用 ssl 时不会“实时更新”

问题描述

我正在创建一个 php 网站,它使用 javascript 每 5 秒从数据库中获取值。

当我在没有 ssl 连接的情况下访问网站时,一切都运行良好,但是只要我在 url 之前键入 https://,页面就会加载,但每 5 秒更新一次的部分会一直停留在加载图像上。

这就是我接收更新的方式

索引.php

<div id="stats">
    <center><img src="/images/loading.gif" alt="Loading stats" title="Loading stats" /></center>
</div>

stats.js

//stats
function loadStats(){
    $.ajax({
        url: 'includes/stats.php',
        success: function(data) {
            $("#stats").html(data);
            setTimeout("loadStats()", 5000);
        }
    });
}
$(function(){
    loadStats();
});

包括/stats.php

Here I receive the databse info and echo the html

提前致谢!

编辑:

I am using //domain/file.js now for all js/css/images but it still only 
works without the ssl connection

标签: javascript

解决方案


看起来 JQuery 没有正确加载。

莱斯利·彼得斯指出:

控制台输出如下: Uncaught ReferenceError: $ is not defined at stats.js:11

第 11 行是:

$(function(){
  loadStats();
});

进行ajax回调的父页面可能没有引用jQuery,此外,请确保通过HTTPS://加载jQuery。

如果这不起作用,您可能需要考虑直接运行:

    function loadStats(){
    $.ajax({
        url: 'includes/stats.php',
        success: function(data) {
            $("#stats").html(data);
            setTimeout("loadStats()", 5000);
           }
   });
   }
   loadStats();

推荐阅读