我正在创建一个php网站,它使用javascript每5秒从数据库中获取值。
当我访问没有ssl连接的网站时,一切都进行得很好,但是当我在url之前输入https://时,页面就会加载,但是每5秒更新一次的部分仍然停留在加载映像上。
我就是这样接收更新的
index.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
发布于 2019-04-30 20:38:56
看起来JQuery的加载不正确。
莱斯利·彼得斯指出:
控制台输出如下: Uncaught:$不是在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();
https://stackoverflow.com/questions/55925797
复制相似问题